1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| from Tkinter import *
def e1():
tex2.configure(text='1')
def e2(event):
#The widget which generated this event. This is a valid Tkinter widget instance, not a name. This attribute is set for all events.
widget = event.widget
#The current mouse position, in pixels.
x, y = event.x, event.y
#The current mouse position relative to the upper left corner of the screen, in pixels.
x_root, y_root = event.x_root, event.y_root
#The character code (keyboard events only), as a string.
char = event.char
#The key symbol (keyboard events only).
keysym = event.keysym
#The key code (keyboard events only).
keycode = event.keycode
#The button number (mouse button events only).
num = event.num
#The new size of the widget, in pixels (Configure events only).
width, height = event.width, event.height
#The event type.
type = event.type
aff = widget._name, str(x), str(y), x_root, y_root, char, keysym, keycode, num, str(width), str(height), type
tex2.configure(text=aff)
fen1 = Tk()
Button(fen1, text="Afficher 1", command=e1).pack()
b1 = Button(fen1, text="Afficher 2")
b1.pack()
b1.bind("<Button-1>", e2) # <--- event géré par mainloop()
tex2=Label(fen1)
tex2.pack()
fen1.mainloop() |
Partager