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()
截圖: