Tkinter Button widget

  • Thread starter Shankar Iyer (siyer
  • Start date
S

Shankar Iyer (siyer

Hi,

I have another Tkinter-related question. At the beginning of my program, a tkinter window is created with six buttons. Each of these buttons is assigned a function that should be executed only when the button is pressed. However, it seems that these functions are all executed once when the button widgets are first created. Why is this the case and how do I prevent this from happening?

Shankar
 
P

Peter Otten

Shankar said:
I have another Tkinter-related question. At the beginning of my
program, a tkinter window is created with six buttons. Each of these
buttons is assigned a function that should be executed only when the
button is pressed. However, it seems that these functions are all
executed once when the button widgets are first created. Why is this
the case and how do I prevent this from happening?

Change your source code from

# wrong
button = Tkinter.Button(..., command=some_function(),...)

to

# correct
button = Tkinter.Button(..., command=some_function,...)

to pass the *function* to the widget instead of the *result* of a function
call. And, next time, remember to post some code alongside with your
question.

Peter
 
F

Fuzzyman

Peter said:
Shankar Iyer ([email protected]) wrote:
[snip..]

Change your source code from

# wrong
button = Tkinter.Button(..., command=some_function(),...)

to

# correct
button = Tkinter.Button(..., command=some_function,...)

to pass the *function* to the widget instead of the *result* of a function
call. And, next time, remember to post some code alongside with your
question.

Nice spot of mind reading there ;-)
I remember getting bitten by this one a while ago....

Regards,


Fuzzy
 
W

William Park

Peter Otten said:
Change your source code from

# wrong
button = Tkinter.Button(..., command=some_function(),...)

to

# correct
button = Tkinter.Button(..., command=some_function,...)

to pass the *function* to the widget instead of the *result* of a
function call. And, next time, remember to post some code alongside
with your question.

Hmm, maybe I should learn Tk + Python. Telepathetic powers of Python
programmers are amazing.

--
William Park <[email protected]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top