Skip to content

Commit 80b0747

Browse files
committed
Update Tkinter Click Binding.py
added comments to explain what all is happening in this example
1 parent bfcc6b7 commit 80b0747

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

3 calcGUI/Tkinter Click Binding.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
'''
2+
This example shows you how you can capture mouse click events in tkinter
3+
'''
4+
#import the library
15
from tkinter import *
2-
6+
#create a window object
37
root = Tk()
4-
8+
#create the function to handle the click events
9+
#note that event is a special object in tkinter that will be generated each time there is a click
510
def callback(event):
11+
#note that we can do other things with our x and y now that we know how to get them
612
print ("clicked at", event.x, event.y)
713

14+
#setup the window size
815
frame = Frame(root, width=400, height=400)
16+
#everything in the window will be considered a button, which calls the callback function when pressed
917
frame.bind("<Button-1>", callback)
18+
#put the sizing and button definition into our window (pack is the simplest method)
1019
frame.pack()
1120

21+
#title the overall window
22+
root.title("Example of capturing a mouse click location.")
23+
#show the window - windows run in a loop listening for the window close button to break the loop
1224
root.mainloop()

0 commit comments

Comments
 (0)