label
from tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop() #进入消息循环
#控件的显示步骤:
#1.创建这个控件
#2.指定这个空间的master,即这个控件属于哪一个
#3.告诉GM(geometry manager)有一个控件产生了
from Tkinter import * root = Tk()
#左对齐,文本居中
Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'yellow',width = 40,height = 3,wraplength = 80,justify = 'left').pack()
#居中对齐,文本居左
Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'red',width = 40,height = 3,wraplength = 80,anchor = 'w').pack()
#居中对齐,文本居右
Label(root,text = 'welcome to jcodeer.cublog.cn',bg = 'blue',width = 40,height = 3,wraplength = 80,anchor = 'e').pack()
root.mainloop()
label = Label(root,fg = 'red',bg = '#FF00FF',text = 'Hello I am Tkinter')
参数: fg:前景颜色
bg:背景颜色
width:宽
height:高
button
from Tkinter import * #定义Button的回调函数
def helloButton():
print ('hello button')
root = Tk()
#通过command属性来指定Button的回调函数
Button(root,text = 'Hello Button',command = helloButton).pack()
root.mainloop()