April 2018
Beginner
340 pages
7h 54m
English
What happens if we bind a key which already has default behavior on the target widget? Let's take a look at one example. You should remember from our text editor example that the combination of Ctrl + O inserted blank lines. We should overwrite that:
import tkinter as tkwin = tk.Tk()text = tk.Text(win, fg="black", bg="white")text.bind('<Control-o>', lambda e, t=text: t.insert(1.0, 'aaa'))text.pack()win.mainloop()
Run this example, type three lines of dummy text, then place your cursor in the middle somewhere. When you press Ctrl + O, you would expect the letters aaa to be inserted at the beginning of the editor. Well, they are, but the default behavior of adding blank lines also happens. If we are going to bind ...