[Tutor] Buttons automatically executing
Phillip Hart
phillip.hart at gmail.com
Wed Jun 15 21:31:55 CEST 2005
Thanks for taking the time to read this.
Excuse me if this falls under the boundaries of a "newbie" question, as I am
a self-taught programmer.
While using Tkinter to create buttons, something unexpected happens when the
button commands call functions. Namely, when I run the following, it
immediately executes the print statements without the button ever being
pressed. Additionally, pressing the button once the Tk window is up will not
activate the button.
#!usr/bin/python
from Tkinter import *
def location(x,y):
print "I am in row ",x," and column ",y
root=Tk()
root.geometry('300x300')
can=Canvas(root,width=250, height=250)
bimage=PhotoImage(file='sq1.gif')
b1=Button(can,bg="black",image=bimage,command=location(0,0)).grid(row=0,column=0)
can.pack()
root.mainloop()
Lastly, when I change the command to be anything other than a function, such
as a print statement, it works fine. What am I doing wrong here?
thanks again for your time and help,
green python user (no pun intended),
-Phillip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050615/262de50b/attachment.htm
More information about the Tutor
mailing list