[Tkinter-discuss] buttonpress
Stewart Midwinter
stewart.midwinter at gmail.com
Tue Apr 25 18:57:44 CEST 2006
Pavel, what operating system are you on, and what version of Python,
and what version of Tcl/Tk?
Also note that to see the code work, you need to click on the button
itself, which might be a bit hard as it is quite narrow. To make the
button wider, give it some text. Also note that the events will be
printed in a console window, not in the application itself.
Below a version of Jeff's test app that shows the events in the
application itself, in a label.
On 4/25/06, Pavel Kosina <geon at post.cz> wrote:
> Unfortunately not with me. This piece of code doesnt work as you wrote
> and/or is described in the link I sent before. (it is about <Button-1> ..)
---
#mouseevent.py
from Tkinter import *
root = Tk()
myEvent = StringVar()
myEvent.set('no event yet')
def print_event(evt):
msg = "Event at", evt.x, evt.y
print msg
myEvent.set(msg)
b = Button(root, text="Press here!")
b.pack()
l = Label(root, textvariable=myEvent,text=myEvent.get() )
l.pack()
b.bind("<B1-Motion>", print_event)
b.mainloop()
More information about the Tkinter-discuss
mailing list