#!/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()
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to