[英]Adding right click option to a frame in Tkinter Python
I am trying to make a simple explorer with tkinter python and I want to add a right click option to the files and folder buttons like copy, cut, delete, etc.我正在尝试使用 tkinter python 制作一个简单的资源管理器,我想在文件和文件夹按钮中添加右键单击选项,例如复制、剪切、删除等。
If somehow I can add a frame to wherever the user has right clicked then I can place all the buttons in that frame.如果以某种方式我可以在用户右键单击的任何位置添加一个框架,那么我可以将所有按钮放在该框架中。
This is the file.这是文件。
Please help and Thanks in advance.请提前帮助和感谢。
Here is an example Tkinter file that has the features you're talking about:这是一个示例 Tkinter 文件,它具有您正在谈论的功能:
import tkinter
from tkinter import *
root = Tk()
L = Label(root, text ="Right-click to display menu",
width = 40, height = 20)
L.pack()
m = Menu(root, tearoff = 0)
m.add_command(label ="Cut")
m.add_command(label ="Copy")
m.add_command(label ="Paste")
m.add_command(label ="Reload")
m.add_separator()
m.add_command(label ="Rename")
def do_popup(event):
try:
m.tk_popup(event.x_root, event.y_root)
finally:
m.grab_release()
L.bind("<Button-3>", do_popup)
mainloop()
Implement it as you need根据需要实施
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.