473,396 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3640
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.