473,493 Members | 4,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Tkinter Button widget

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

Jul 21 '05 #1
3 1796
Shankar Iyer (si***@Princeton.EDU) wrote:
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


Jul 21 '05 #2


Peter Otten wrote:
Shankar Iyer (si***@Princeton.EDU) 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
Peter


Jul 21 '05 #3
Peter Otten <__*******@web.de> wrote:
Shankar Iyer (si***@Princeton.EDU) wrote:
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.


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

--
William Park <op**********@yahoo.ca>, 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/
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6991
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
6
6070
by: Elaine Jackson | last post by:
I've got a script where a button gets pushed over and over: to cut down on the carpal tunnel syndrome I'd like to have the button respond to presses of the Enter key as well as mouse clicks; can...
1
2236
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
2
2926
by: Tonino | last post by:
Hi, I have a small Tkinter app that gets data from a socket connection to a "server". The app has a Text() widget to display the info that it gets from the socket connection. I have the...
7
4519
by: Harlin Seritt | last post by:
I was looking at the Tcl/Tk sourceforge page and found that there were a couple of new widgets being produced for Tcl 8.5. Does anyone know if there are any Tkinter wrappers somewhere? thanks, ...
0
2334
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
1440
by: Avi Kak | last post by:
Does Tkinter provide a function that returns all the event descriptors for a given widget class? I am looking for something similar to what you get in Perl/Tk when you call bind() with a single...
0
1408
by: Svenn Bjerkem | last post by:
Hi, Armed with Programming Python 3rd Edition and Learning Python 2nd edition I try to write an application which I at first thought was simple, at least until I was finished with the GUI and...
7
2300
by: =?iso-8859-1?q?Xavier_B=E9rard?= | last post by:
Hello everyone, I am wondering if there is a way to use custom drawing in Tkinter. I've been using it for few months, and all I know about custom drawing is to draw directly on a Canvas with...
3
3899
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.