Добрый день. Кто знает как можно проксировать в tk клавишу "Control" или сочетание "Control" + "v" or "c"?
Вот пример кода:
import tkinter as tk
class MyTextClass(tk.Text):
def
init(self, *args, **kwargs):
tk.Text.
init(self, *args, **kwargs)
# create a proxy for the underlying widget
self._orig = self._w + '_orig'
self.tk.call('rename', self._w, self._orig)
self.tk.createcommand(self._w, self._proxy)
def _proxy(self, command, *args):
cmd = (self._orig, command) + args
result =
self.tk.call(cmd)
if command in ('insert', 'delete', 'replace'):
self.event_generate('<<OtherKeys>>')
return result
root = tk.Tk()
label = tk.Label(root, anchor='w')
text = MyTextClass(root, width=80, height=20)
label.pack(side='bottom', fill='x')
text.pack(side='top', fill='both', expand=True)
def other_keys(event):
print('Other keys')
def press_control(event):
print('Press control')
text.bind('<<PressControl>>', press_control)
text.bind('<<OtherKeys>>', other_keys)
root.mainloop()