日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command)

發布時間:2025/3/21 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python之tkinter:動態演示調用python庫的tkinter帶你進入GUI世界(Menu的Command)

?

目錄

tkinter應用案例

1、添加菜單欄組件

2、tkinter應用案例:添加右鍵彈出菜單


?

?

tkinter應用案例

1、添加菜單欄組件

#tkinter應用案例:添加菜單欄組件 #繪制思路:利用超小的橢圓作為筆點 from tkinter import * import math as mroot = Tk() root.title("Jason niu工作室") theLabel=tk.Label(root,text="進入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應用案例:添加右鍵彈出菜單

#tkinter應用案例:添加右鍵彈出菜單 from tkinter import * import math as mroot = Tk() root.title("Jason niu工作室") theLabel=tk.Label(root,text="進入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()

?

?

?

?

?

總結

以上是生活随笔為你收集整理的Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Menu的Command)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。