472,982 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Tkinter--unexpected behavior with pack_forget()

I'm trying to toggle the visibility of a Tkinter widget using
pack_forget(), and I'm running into unexpected behavior. The widget
"hides" correctly, but does not become visible again. My sample code is
below:

----
from Tkinter import *

root = Tk()

label = Label(text="Hello")
label.pack()

def toggle():
if label.winfo_ismapped:
print "mapped"
label.pack_forget()
else:
label.pack()

button = Button(text="Push me", command=toggle)
button.pack()

root.mainloop()
-----

The expected behavior is for the label to hide ("pack_forget()") if
label.winfo_ismapped returns true. That works as . However, I would also
expect the widget to be displayed/packed if it is not mapped. What
happens instead is that the label is apparently mapped even after I call
label.pack_forget().

Can anyone point out what I'm doing wrong? Calling "pack forget" from
Tcl maps/unmaps the widget as expected. In this case, I can't quite
figure out where my error is.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Dec 21 '07 #1
1 3601
Kevin Walzer wrote:
I'm trying to toggle the visibility of a Tkinter widget using
pack_forget(), and I'm running into unexpected behavior. The widget
"hides" correctly, but does not become visible again. My sample code is
below:

----
from Tkinter import *

root = Tk()

label = Label(text="Hello")
label.pack()

def toggle():
if label.winfo_ismapped:
print "mapped"
label.pack_forget()
else:
label.pack()

button = Button(text="Push me", command=toggle)
button.pack()

root.mainloop()
-----

The expected behavior is for the label to hide ("pack_forget()") if
label.winfo_ismapped returns true. That works as . However, I would also
expect the widget to be displayed/packed if it is not mapped. What
happens instead is that the label is apparently mapped even after I call
label.pack_forget().

Can anyone point out what I'm doing wrong? Calling "pack forget" from
Tcl maps/unmaps the widget as expected. In this case, I can't quite
figure out where my error is.


if label.winfo_ismapped: always evaluates to True.

Instead, you need,

if label.winfo_ismapped():

Dec 21 '07 #2

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

Similar topics

12
by: Dave Rahardja | last post by:
Does the C++ standard specify the behavior of floating point numbers during "exceptional" (exceptional with respect to floating point numbers, not exceptions) conditions? For example: double...
19
by: E. Robert Tisdale | last post by:
In the context of the comp.lang.c newsgroup, the term "undefined behavior" actually refers to behavior not defined by the ANSI/ISO C 9 standard. Specifically, it is *not* true that "anything can...
23
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64...
38
by: Steven Bethard | last post by:
> >>> aList = > >>> it = iter(aList) > >>> zip(it, it) > > That behavior is currently an accident. >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416
7
by: Mike Livenspargar | last post by:
We have an application converted from v1.1 Framework to v2.0. The executable references a class library which in turn has a web reference. The web reference 'URL Behavior' is set to dynamic. We...
66
by: gyan | last post by:
Hi All, I am using sprintf and getting starnge output in following case char temp_rn; memset(temp_rn,'\0',12); sprintf(temp_rn,"0%s",temp_rn); the final value in temp_rn is 00 how it...
12
by: Rajesh S R | last post by:
Can anyone tell me what is the difference between undefined behavior and unspecified behavior? Though I've read what is given about them, in ISO standards, I'm still not able to get the...
28
by: v4vijayakumar | last post by:
#include <string> #include <iostream> using namespace std; int main() { string str; str.resize(5); str = 't';
35
by: bukzor | last post by:
I've found some bizzare behavior when using mutable values (lists, dicts, etc) as the default argument of a function. I want to get the community's feedback on this. It's easiest to explain with...
33
by: coolguyaroundyou | last post by:
Will the following statement invoke undefined behavior : a^=b,b^=a,a^=b ; given that a and b are of int-type ?? Be cautious, I have not written a^=b^=a^=b ; which, of course, is undefined....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.