Bind mouse action to a method : Frame « Tkinker « Python Tutorial






Bind mouse action to a method
from Tkinter import *
def ShowPosition(event):
    Top = Toplevel(root)
    xlabel = Label(Top)
    xlabel.pack()
    xlabel.config(text = "X = " + str(event.x))
    ylabel = Label(Top)
    ylabel.pack()
    ylabel.config(text = "Y = " + str(event.y))
    Top.mainloop()

root = Tk()
frame = Frame(root, width=200, height=200)
frame.bind("<Button-1>", ShowPosition)
frame.pack()
root.mainloop()








18.14.Frame
18.14.1.Demonstrates creating a windowDemonstrates creating a window
18.14.2.Frame with three buttonsFrame with three buttons
18.14.3.Set size of main windowSet size of main window
18.14.4.Add button to frameAdd button to frame
18.14.5.Bind mouse action to a methodBind mouse action to a method
18.14.6.Two top level windowsTwo top level windows
18.14.7.Destroy a frameDestroy a frame
18.14.8.Set window title for main frameSet window title for main frame