Python图形用户界面

1.使用Tkinter创建图形用户界面的步骤

(1)导入Tkinter模块,使用import Tkinter或from Tkinter import *

(2)创建顶层窗口对象容器,使用top = Tkinter.Tk()

(3)在顶层窗口对象上创建GUI对象

(4)将GUI对象与底层程序代码相连接

(5)进入主事件循环

例如:

# !/usr/bin/env python

import Tkinter

top = Tkinter.Tk()
label = Tkinter.Label(top, text="Hello, World")
label.pack()
Tkinter.mainloop()
# !/usr/bin/env python


import Tkinter
top = Tkinter.Tk()

hello_label = Tkinter.Label(top, text="Hello, World")
hello_label.pack()

quit_button = Tkinter.Button(top, text="Quit", command=top.quit,  bg="pink", fg="blue")
quit_button.pack(fill=Tkinter.X, expand=1)

Tkinter.mainloop()

猜你喜欢

转载自www.cnblogs.com/liuzhiqaingxyz/p/9028295.html