From the course: Python GUI Development with Tkinter
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Binding to mouse events
From the course: Python GUI Development with Tkinter
Binding to mouse events
- [Instructor] When binding handler functions or methods to keyboard events, we typically bind to top level window widgets so that the keyboard events are captured whenever that window has focus. With mouse events, on the other hand, we may only want to trigger events when the user interacts with one specific widget amongst the many in our program using their mouse. For this reason, it's more common to bind mouse events to individual widgets within the program. In this video, I'll demonstrate this by binding mouse events to a canvas widget to create a simple drawing program. I'm going to start by opening the exercise files, Chapter Seven folder, and creating a copy of our template Python file. I'll rename this copy to 03_mouse, because we'll be covering mouse events. And then I'll right click on it to edit it with idle. Now in this template, I'll start by creating a new canvas object, which I'll assign to a variable called canvas. It'll be a child of the root. I'll give it a width of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.