Tkinter mouse event initially triggered

Posted by user3714884 on Stack Overflow See other posts from Stack Overflow or by user3714884
Published on 2014-06-08T15:20:49Z Indexed on 2014/06/08 15:24 UTC
Read the original article Hit count: 172

Filed under:
|
|
|

I'm currently learning Tkinter and I cannot find a solution for my problem here nor outside Stackoverflow. In a nutshell, all events that I bind to my widgets are triggered initialy and don't respond to my actions.

In this example, the red rectangle appears on the canvas when I run the code, and color=random.choice(['red', 'blue']) revealed that the event binding doesn't work after that:

import Tkinter as tk

class application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.can = tk.Canvas(master, width=200, height=200)
        self.can.bind('<Button-2>', self.draw())
        self.can.grid()
    def draw(self):
        self.can.create_rectangle(50, 50, 100, 100, fill='red')

app = application()
app.mainloop()

I use a Mac platform, but I haven't got a clue about its role in the problem. Could anyone please point me at the mistake i did here?

© Stack Overflow or respective owner

Related posts about python

Related posts about osx