O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required