python使用Tkinter編寫GUI

       如果需要在Tkinter的窗口、組件中顯示中文,除了在“.py”腳本文件中的首行添加“#-*-coding:utf-8-*-”指明字符編碼之外,還應該將腳本保存成"UTF-8"的編碼格式。

#-*- coding:utf-8 -*-
#file:TkinterWindow.py
#
import Tkinter                                   #導入Tkinter模塊
root=Tkinter.Tk()                                #生成root主窗口
label=Tkinter.Label(root,text="Hello,Tkinter!")  #生成標籤
label.pack()                                     #將標籤添加到root主窗口
button1=Tkinter.Button(root,text="Button1")      #生成button1
button1.pack(side=Tkinter.LEFT)                  #將button1添加到root主窗口
button2=Tkinter.Button(root,text="Button2")
button2.pack(side=Tkinter.RIGHT)
root.mainloop()                                  #進入消息循環


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章