[Tutor] tkinter events: <B1-Motion>
Zsiros Levente
zslevi at sch.bme.hu
Mon Aug 21 15:36:32 CEST 2006
/#!/usr/bin/python/
/# In this program I wanted to write the event <B1-Motion> on my own, combining <Button-1>, <Motion> and <ButtonRelease-1>,
# but unfortunetly it doesn't work. No syntax errors.
/ from Tkinter import *
*def* handler(event):
*if* buttonpressed == 1 :
/#if the mousebutton is pressed and moved, circles should appear, but they do not/
can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, fill="orange")
lab.config(text='buttonpressed=' + str(buttonpressed) )
*def* press(event):
buttonpressed=1
lab2.config(text=buttonpressed)
*def* release(event):
buttonpressed=0
lab2.config(text=buttonpressed)
r=5
/#global buttonpressed/
buttonpressed=0
root = Tk()
root.geometry('600x500+200+200')
/# both labels are used to check the status of the variable buttonpressed/
lab = Label(root, text='cucc')
lab2 = Label(root, text='cucc2')
can = Canvas(root, width='500', height='400', bg='white')
can.bind("<Motion>",handler)
can.bind("<Button-1>",press)
can.bind("<ButtonRelease-1>",release)
lab.pack()
lab2.pack()
can.pack()
root.mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060821/e5257b0c/attachment-0001.html
More information about the Tutor
mailing list