close
這個資料也是在我研究所時期所作的一些研究,因為當時要用 Python 撰寫一些程式,又苦無視窗介面所以閱讀了這個視窗環境的資料。
完成TKinter程式需要做捯下面三件事情:
import Tkinter #將TK模組載入
root=Tkinter.Tk() #建立主視窗
root.mainloop() #建立事件迴圈
上面是一個最基本的視窗程式
def main():
global root, history_frame, info_line
root = Tkinter.Tk()
root.title('Txt2Html TK Shell')
init_vars()
#-- Create the menu frame, and menus to the menu frame
menu_frame = Tkinter.Frame(root)
menu_frame.pack(fill=Tkinter.X, side=Tkinter.TOP)
menu_frame.tk_menuBar(file_menu(), action_menu(), help_menu())
#-- Create the history frame (to be filled in during runtime)
history_frame = Tkinter.Frame(root)
history_frame.pack(fill=Tkinter.X, side=Tkinter.BOTTOM, pady=2)
#-- Create the info frame and fill with initial contents
info_frame = Tkinter.Frame(root)
info_frame.pack(fill=Tkinter.X, side=Tkinter.BOTTOM)
# first put the column labels in a sub-frame
LEFT, Label = Tkinter.LEFT, Tkinter.Label # shortcut names
label_line = Tkinter.Frame(info_frame, relief=Tkinter.RAISED, borderwidth=1)
label_line.pack(side=Tkinter.TOP, padx=2, pady=1)
Label(label_line, text="Run #", width=5).pack(side=LEFT)
Label(label_line, text="Source:", width=20).pack(side=LEFT)
Label(label_line, text="Target:", width=20).pack(side=LEFT)
Label(label_line, text="Type:", width=20).pack(side=LEFT)
Label(label_line, text="Proxy Mode:", width=20).pack(side=LEFT)
# then put the "next run" information in a sub-frame
info_line = Tkinter.Frame(info_frame)
info_line.pack(side=Tkinter.TOP, padx=2, pady=1)
update_specs()
#-- Finally, let's actually do all that stuff created above
root.mainloop()
參考資料:
Python/Tkinter(Tk)
中文線上資料(含範例)
Tkinter線上說明文件
有關Python GUI相關的說明文件
線上教學課程
一些程式範例
wxWindows Python GUI toolkit
類別架構說明文件
環境設定:
更改c:\Python23\Lib\site.py(因中文在windows要用unicode):
把
encoding = 'ascii'
改成
encoding = 'mbcs
全站熱搜
留言列表