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()

截圖:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM