首页 > 代码库 > Tkinter学习笔记-1

Tkinter学习笔记-1

Tkinter

python标准GUI包,提供了Tk GUI工具箱的OO接口

每个组件继承自Widget

GUI由包含子组件的顶层组件构成

Frame类作为顶层组件

 

标签

显示文本、图片、提示信息

通过Label类创建

 1 # SimpleLabel.py 2 # Label demonstration 3  4 from Tkinter import * 5  6 class LabelDemo( Frame ): 7     """ Demonstrate Labels""" 8  9     def __init__(self):10         """ Create three Labels and pack them """11 12         Frame.__init__( self )  # initialize Frame object13 14         # frame files all available space15         self.pack( expand = YES, fill = BOTH)16         self.master.title( "Labels" )17 18         self.Label1 = Label( self, text = "Label with text" )19 20         # resize frame to accommodate Label21         self.Label1.pack()22 23         self.Label2 = Label( self, text = "Labels with text and bitmap" )24 25         # insert Label against left side of frame26         self.Label2.pack( side = LEFT )27 28         # using default bitmap image as label29         self.Label3 = Label( self, bitmap = "warning" )30         self.Label3.pack( side = LEFT )31 32 33 demo = LabelDemo()34 35 demo.mainloop()   # starts event loop

 

Tkinter学习笔记-1