python_界面编程

来源:互联网 发布:中性粒细胞 知乎 编辑:程序博客网 时间:2024/05/18 00:31

 
代码:
import Tkinter
top = Tkinter.Tk() 
label = Tkinter.Label(top, text='hello wrold' )
label.pack()  #管理和显示组件
Tkinter.mainloop()
 
 
 
import Tkinter
#按钮的使用
top = Tkinter.Tk()
button = Tkinter.Button(top, text='exit', command=top.quit)
button.pack()
Tkinter.mainloop()
 
 
 
import Tkinter
#按扭和标签的使用
top = Tkinter.Tk()
label = Tkinter.Label(top, text='hello,world')
label.pack()
 
button = Tkinter.Button(top, text='exit', command=top.quit, bg='red', fg='white')
button.pack(fill=Tkinter.X, expand=1)
 
Tkinter.mainloop()
 
 
 
#用标签控制字体大小
import Tkinter
def resize(ev=None):
    label.config(font='Helvetica -%d bold' % \
                 scale.get())
 
top = Tkinter.Tk()
top.geometry('250x150')
 
label = Tkinter.Label(top, text='hello,world',\
                      font='Helvetica -12 bold')
label.pack(fill=Tkinter.Y, expand=1)
 
scale = Tkinter.Scale(top, from_=10, to=40,\
                      orient=Tkinter.HORIZONTAL, command=resize)
scale.set(12)
scale.pack(fill=Tkinter.X, expand=1)
 
top.mainloop()