标签Label、按钮Buttn、输入框Entry这些都是python的控件,那么他们如何使用呢?
标签Label:可以显示文本和位图
from tkinter import * root = Tk() root.minsize(300, 200) text = " I want to study PYTHON" label = Label(root, text = text, fg ="black", bg="red") label.pack(side = LEFT) root.mainloop()
tkinter 是Python内置的GUI工具的模块,各种控件都在其中定义。编制窗口交互的应用程序都需要导入。
root = Tk()生成一个底层窗口。然后定义Label类的对象,连个必须的参数:父空间和文字内容。定义了空间以后必须用pack()函数保证才能显示。最后一行root.mainloop()是必须的,它令根空间进入主循环,开始监听事件和执行相应的人机交互命令。
按钮Button:在程序中显示按钮。
from tkinter import * root = Tk() root.title("Button demo") root.minsize (300, 200) Button(root, text = "禁用" ,state = DISABLED).pack(side=LEFT) Button(root, text = "取消" ).pack(side=LEFT) Button(root, text = "确定" ).pack(side=LEFT) Button(root, text = "退出" , command= root.quit).pack(side=RIGHT) root.mainloop()
要使按钮不能用,可见参数state = DISABLED,不见当然默认是可用的。
DISABLED是tkinter 值预定义的常量。state 和前面的text= 都是控件的购置函数中
的变量名, 不看任意更改,root 不是。
输入框Entry:用于显示简单的文本内容
from tkinter import * root = Tk() root.title("Entry demo") root.minsize (400, 200) f1 = Frame(root) f2 = Frame(root) e1 = StringVar() e1.set("输入框默认内容") e2 = StringVar() e2.set("不可修改的内容") Label(f1, text="标准输入框").pack(side=LEFT, padx=5, pady=5) Entry (f1, width = 20, textvariable = e1).pack(side=LEFT) Label(f2, text="禁用输入框").pack(side=LEFT, padx=5, pady=5) Entry(f2, width = 20, textvariable = e2, state=DISABLED).pack(side=LEFT) f1.pack() f2.pack() root.mainloop()
输入框即单行文本框。Entry 有参数textvariable 是文本框中显示的字符串。
使用StringVar()函数定义一个字符串变量,类型确定但没有赋值。
以上是python控件怎么用的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonisehybridmodelofcompilationand interpretation:1)thepythoninterspretercompilesourcececodeintoplatform- interpententbybytecode.2)thepytythonvirtualmachine(pvm)thenexecuteCutestestestesteSteSteSteSteSteSthisByTecode,BelancingEaseofuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允许fordingfordforderynamictynamictymictymictymictyandrapiddefupment,尽管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知识之际,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations则youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concateNateListsinpythonwithTheSamelements,使用:1)operatototakeepduplicates,2)asettoremavelemavphicates,or3)listCompreanspearensionforcontroloverduplicates,每个methodhasdhasdifferentperferentperferentperforentperforentperforentperfortenceandordormplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允许ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

禅工作室 13.0.1
功能强大的PHP集成开发环境

WebStorm Mac版
好用的JavaScript开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6
视觉化网页开发工具