Events in our text editor

First things first: we should ensure that we have some expected key-bindings happening within our Text widget. We'll collate these in a method called bind_events and call this method from within our __init__:

def __init__(self):    ...        self.bind_events()def bind_events(self):    self.bind('<Control-a>', self.select_all)    self.bind('<Control-c>', self.copy)    self.bind('<Control-v>', self.paste)    self.bind('<Control-x>', self.cut)    self.bind('<Control-y>', self.redo)    self.bind('<Control-z>', self.undo)

This function now ensures that six commonly used keyboard shortcuts will perform their expected behaviors.

Since these behaviors are already handled by the Text widget (except for select_all), we only need to emit the relevant ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.