from Tkinter import *

class ButtonHandler:
    
    def __init__(self):
        
      
        self.root = Tk()
        self.root.geometry('600x500+200+200')

        self.label = Label(self.root, text=str(self.mousedown))
        self.can = Canvas(self.root, width='500', height='400', bg='white')
      
        self.can.bind("<Motion>",lambda x:self.handler(x,'motion'))
        self.can.bind("<Button-1>",lambda x:self.handler(x,'press'))
        self.can.bind("<ButtonRelease-1>",lambda x:self.handler(x,'release'))
        self.label.pack()
        self.can.pack()
        self.root.mainloop()
    
    def mouseDown(self, event ):
	return 1
	
    def handler(self,event,x):
     
        if x == 'press':
            self.mousedown = 1
        elif x == 'release':
            self.mousedown = 0
        elif x == 'motion':
            if self.mousedown:
                
                r = 5
                self.can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, fill="orange")
	self.label.config(text=str(self.mousedown))
        

x = ButtonHandler()
#x.__init__()
from Tkinter import *

class ButtonHandler:
    
    def __init__(self):
        
      
        self.root = Tk()
        self.root.geometry('600x500+200+200')

        self.mousedown = False
        self.label = Label(self.root, text=str(self.mousedown))
        self.can = Canvas(self.root, width='500', height='400', bg='white')
      
        self.can.bind("<Motion>",lambda x:self.handler(x,'motion'))
        self.can.bind("<Button-1>",lambda x:self.handler(x,'press'))
        self.can.bind("<ButtonRelease-1>",lambda x:self.handler(x,'release'))
        self.label.pack()
        self.can.pack()
        self.root.mainloop()
    
    def handler(self,event,x):
        print('Handler %s' % x) 
        if x == 'press':
            self.mousedown = True
        elif x == 'release':
            self.mousedown = False
        elif x == 'motion':
            if self.mousedown:               
                r = 5
                self.can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, fill="orange")
        self.label.config(text=str(self.mousedown))
        

x = ButtonHandler()

Check your indentation setting, your code was inconsistent. x is maybe not the best choice of parameter name.

How is it going? This thread is still not solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.