python之tkinter使用举例-Button

tkinter用于编写GUI界面,python3默认已经包含,直接使用。
 1 # GUI:tkinter使用举例
 2 import tkinter
 3 
 4 # 实例化tkinter对象
 5 top = tkinter.Tk()
 6 top.geometry('220x60')  # 设置窗口大小
 7 top.title('tkinter使用举例')  # 设置窗口标题
 8 
 9 # 新建Label控件对象,显示"Hello World"
10 label = tkinter.Label(top, text='Hello World')
11 # 加载Label控件
12 label.pack()
13 
14 # 新建Button控件
15 quit_btn = tkinter.Button(top, text='quit', command=top.quit, bg='red', fg='white')
16 # 设置按钮填充所有横向空间
17 quit_btn.pack(fill=tkinter.X, expand=1)
18 
19 # 循环运行
20 tkinter.mainloop()

截图:

 

 

posted @ 2017-11-01 12:11  星瑞  阅读(3912)  评论(0编辑  收藏  举报