External Exam Download Resources Web Applications Games Recycle Bin

More Events

other events.py

from tkinter import *
from tkinter import messagebox
window = Tk()

#CONTROLS + VARIABLES:
frame = Frame(width=100, height=100)

#EVENTS:
def keyed(event):
    messagebox.showinfo("keyed", event.char)

def clicked(event):
    messagebox.showinfo("clicked",
                        "x: " + str(event.x) +
                        ", y: " + str(event.y))

#BINDINGS:
frame.bind("<Button-1>", clicked)
frame.bind("<Key>", keyed)

#PACK:
frame.pack()

#RUN:
frame.focus_set() #frame wont receive key events without this
window.mainloop()