產生第一個視窗 Create a window
產生第一個視窗 Create a window
Example Code
- import sys
- if sys.version_info[0] < 3:
- import Tkinter as tk
- else:
- import tkinter as tk
- win=tk.Tk()
- win.title("TITLE")
- win.mainloop()
Note and Comments
- import sys 匯入作業系統模組(函式庫)
- sys.version_info[0] 回報作業系統中Python版本
- if sys.version_info[0] < 3: 如果作業系統中Python版本小於執行import Tkinter as tk
- import Tkinter as tk 匯入視窗程式模組(函式庫) 並命名爲tk 不同版本的python在引入函式庫時大小寫不同
- win=tk.Tk() 初始化tk函式庫的視窗物件並宣告爲win
- win.title("TITLE") 給定視窗的標題
- win.mainloop()執行顯示win物件
result
設定視窗大小 setup the size of the window
設定視窗大小 setup the size of the window
Example Code
- import Tkinter as tk
- win=tk.Tk()
- win.title("Title")
- win.geometry('800x600') #set a 800*600 window
- win.resizable(0, 0) #fix the size of window
- win.mainloop()
Note and Comments
- import Tkinter as tk 匯入視窗程式模組(函式庫) 並命名爲tk 注意:不同版本的python在引入函式庫時大小寫不同
- win.geometry('800x600') #set a 800*600 window ; 設定視窗大小爲800*600
- win.resizable(0, 0) #fix the size of window 將視窗的X,Y大小設定不可調整
result