本人想開發一個簡易的搜圖GUI,基於此,選擇用Tkinter模塊開發。
需要開發出菜單欄
1 from Tkinter import * 2 3 4 root = Tk() 5 root.title("搜圖助手") 6 root.geometry("500x500+600+200") 7 help = tkMessageBox.showinfo("歡迎", "歡迎使用搜圖助手!\nBy Johnson") 8 def hello(): 9 print "Hello " 10 menubar = Menu(root) 11 filemenu = Menu(menubar, tearoff=0) 12 filemenu.add_command(label="上一張", command=hello) 13 filemenu.add_command(label="下一張",command=hello) 14 filemenu.add_separator() 15 filemenu.add_command(label="保存",command=hello) 16 filemenu.add_command(label="查看",command=hello) 17 menubar.add_cascade(label="菜單",menu=filemenu) 18 helpmenu = Menu(menubar, tearoff=0) 19 helpmenu.add_command(label="關於", command=hello) 20 helpmenu.add_separator() 21 helpmenu.add_command(label="使用方法",command=hello) 22 menubar.add_cascade(label="幫助", menu=helpmenu) 23 root.config(menu=menubar) 24 root.mainloop()
代碼如上
add_cascade方法添加菜單欄和下拉欄
add_separator方法添加分割線
congfig配置菜單欄
效果如圖




本人Python菜鳥如果錯誤請包涵並指正。
