-3
from Tkinter import *

class Program:    
    def __init__(self):
        b = Button(text="click me", command=self.callback("1"))
        b.pack()

    def callback(self,s):
        print "clicked!"

program = Program()

mainloop()     

why execut function befor click button ?? */

Ala'a Hamda
  • 31
  • 1
  • 9

1 Answers1

0

You should pass a function reference to command argument . Otherwise you execute the function in place.

b = Button(text="click me", command=self.callback)
# Or if you want to pass parameters
b = Button(text="click me", command=lambda: self.callback("1"))
Alexander
  • 12,424
  • 5
  • 59
  • 76