啥也不说直接上代码,有问题或是其它功能在下方评论留言
from tkinter import *
import webbrowser
root=Tk()
root.geometry("500x300")
menubar = Menu(root,tearoff=False)#创建一个菜单
out_text=Text(root)
out_text.grid()
out_text.bind("<Button-3>", lambda x: rightKey(x, out_text))#绑定右键鼠标事件
def cut(editor, event=None):
editor.event_generate("<<Cut>>")
def copy(editor, event=None):
editor.event_generate("<<Copy>>")
def paste(editor, event=None):
editor.event_generate('<<Paste>>')
def open(url, event=None):
webbrowser.open(url)
def rightKey(event, editor):
menubar.delete(0,END)
menubar.add_command(label='剪切',command=lambda: cut(editor))
menubar.add_command(label='复制',command=lambda: copy(editor))
menubar.add_command(label='粘贴',command=lambda: paste(editor))
menubar.add_command(label='打开链接', command=lambda: open(out_text.get(SEL_FIRST, SEL_LAST)))
menubar.post(event.x_root, event.y_root)
if __name__=='__main__':
root.mainloop()