從哪裏?tkinter?進口?*
根?=?Tk()
Root.title('嘗試文本框的右鍵菜單')
root.resizable(False,假)
root . geometry(" 300 x100+200+20 ")
標簽(根,Text= '這裏是剛生成的文本框,試試吧')。包裝(側面= "頂部")
標簽(根)。包裝(側面= "頂部")
秀?=?字符串變量()
入門?=?條目(根,textvariable=show,?寬度="30 ")
Entry.pack()
班級?部分:
def?onPaste(自己):
嘗試:
self.text?=?root.clipboard_get()
除了?TCL錯誤:
及格
show.set(str(self.text))
def?onCopy(自身):
self.text?=?Entry.get()
root . clipboard _ append(self . text)
def?onCut(自我):
self.onCopy()
嘗試:
Entry.delete('sel.first ',?sel.last ')
除了?TCL錯誤:
及格
節?=?第節()
菜單?=?菜單(根,撕裂=0)
Menu.add_command(label= "copy ",?command=section.onCopy)
menu.add_separator()
Menu.add_command(label= "paste ",?command=section.onPaste)
menu.add_separator()
Menu.add_command(label= "cut ",?command=section.onCut)
def?彈出菜單(事件):
menu.post(event.x_root,?event.y_root)
entry . bind(" & lt;Button-3 >,?popupmenu)
root.mainloop()