Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command)
生活随笔
收集整理的這篇文章主要介紹了
Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Python之tkinter:動態(tài)演示調(diào)用python庫的tkinter帶你進(jìn)入GUI世界(Menu的Command)
?
目錄
tkinter應(yīng)用案例
1、添加菜單欄組件
2、tkinter應(yīng)用案例:添加右鍵彈出菜單
?
?
tkinter應(yīng)用案例
1、添加菜單欄組件
#tkinter應(yīng)用案例:添加菜單欄組件 #繪制思路:利用超小的橢圓作為筆點 from tkinter import * import math as mroot = Tk() root.title("Jason niu工作室") theLabel=tk.Label(root,text="進(jìn)入GUI世界,請開始你的表演!\n(利用Menu組件添加菜單欄!)") theLabel.pack() def callback():print (u"歡迎來到Jason niu工作室~")menubar=Menu(root)filemenu = Menu(menubar,tearoff=False) filemenu.add_command(label="打開",command=callback) filemenu.add_command(label="保存",command=callback) filemenu.add_separator() filemenu.add_command(label="退出",command=root.quit) menubar.add_cascade(label="文件",menu=filemenu) editmenu = Menu(menubar,tearoff=False) editmenu.add_command(label="剪切",command=callback) editmenu.add_command(label="拷貝",command=callback) editmenu.add_command(label="粘貼",command=callback) menubar.add_cascade(label="編輯",menu=editmenu)root.config(menu=menubar) mainloop()?
?
2、tkinter應(yīng)用案例:添加右鍵彈出菜單
#tkinter應(yīng)用案例:添加右鍵彈出菜單 from tkinter import * import math as mroot = Tk() root.title("Jason niu工作室") theLabel=tk.Label(root,text="進(jìn)入GUI世界,請開始你的表演!\n(利用Menu組件添加右鍵彈出菜單!)") theLabel.pack() def callback():print (u"歡迎來到Jason niu工作室~")menubar=Menu(root) menubar.add_command(label="撤銷",command=callback) menubar.add_command(label="重做",command=root.quit)frame=Frame(root,width=300,height=200) def popup(event): #menubar.post(event.x_root,event.y_root) frame.bind("<Button-3>",popup) mainloop()?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python之tkinter:动态演示调
- 下一篇: Py之qrcode:Python包之qr