473,569 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter pack bug in Python 2.3


The compact form of pack behaves differently (and I believe incorrectly)
compared to the long form. The following two scripts demonstrate it, at
least on this interpreter:
Python 2.3.2 (#1, Oct 9 2003, 12:03:29)
[GCC 3.3.1 (cygming special)] on cygwin
# First script, no bug

# I want a canvas inside a frame inside a toplevel, with the canvas
# filling the toplevel even as I resize the window. This does it.

from Tkinter import *

root = Tk()
frame = Frame(root, bg="lightBlue" )
frame.pack(side =TOP, expand=1, fill=BOTH)
canvas = Canvas(frame, bg="lightGreen" )
canvas.pack(sid e=TOP, expand=1, fill=BOTH)

mainloop()

# Second script, bug

# I want a canvas inside a frame inside a toplevel, with the canvas
# filling the toplevel even as I resize the window. This doesn't do
# it, and instead makes the canvas a sibling of the frame, instead of
# a child. (Try resizing the toplevel and you'll see.) Why?

from Tkinter import *

root = Tk()
frame = Frame(root, bg="lightBlue") .pack(side=TOP, expand=1, fill=BOTH)
canvas = Canvas(frame, bg="lightGreen" ).pack(side=TOP , expand=1, fill=BOTH)

mainloop()

Frank (filologo disneyano) http://www-lce.eng.cam.ac.uk/~fms27/
Jul 18 '05 #1
2 1907
Frank Stajano wrote:

The compact form of pack behaves differently (and I believe incorrectly)
compared to the long form. The following two scripts demonstrate it, at
There is no "compact form", see below.

[...]
# Second script, bug

# I want a canvas inside a frame inside a toplevel, with the canvas
# filling the toplevel even as I resize the window. This doesn't do
# it, and instead makes the canvas a sibling of the frame, instead of
# a child. (Try resizing the toplevel and you'll see.) Why?

from Tkinter import *

root = Tk()
frame = Frame(root, bg="lightBlue") .pack(side=TOP, expand=1, fill=BOTH)
You are assigning the result of the pack() method, i. e. None, to frame
here, and consequently Canvas is constructed with None instead of a Frame
instance as the first argument.
canvas = Canvas(frame, bg="lightGreen" ).pack(side=TOP , expand=1,
fill=BOTH)

mainloop()


Peter
Jul 18 '05 #2

"Frank Stajano" <fm***@cam.ac.u k

Old Perl programmer, hmm... ;-)

Kindly
MichaelP
Jul 18 '05 #3

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

Similar topics

3
7012
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 import * class App:
2
3233
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make. My button bar is implemented a Frame subclass, which takes the button dictionary as an argument and displays the buttons on the screen: class...
6
6075
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 somebody clue me in regarding how this is done? Muchas gracias. Peace
2
3579
by: Mark English | last post by:
Is there a safe way to run tkinter in a multithreaded app where the mainloop runs in a background thread ? Here's some test code demonstrating the problem. I'm running Python2.4 under Windows 2000. ----------------Code snip starts------------- from Tkinter import * def GetTkinterThread():
5
2991
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. the user can create ("Scrivi") a record with his second name, first name and date of birth, save ("Salva") the record to a file or read in ("Leggi") a...
1
2656
by: C D Wood | last post by:
To whom this may concern, Below is the source code, which demonstrates a problem I am having making a GUI for my python project work. 'table.txt' is a file that is read from the same folder. My code writes to a text file 'table.txt', and 'table.txt' is displayed in
1
3588
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings...
5
3521
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: Current entry Company : entered co. name First entry : entered stuff The second entry: more entered stuff
4
2152
by: MartinRinehart | last post by:
Everything I've read about Tkinter says you create your window and then call its mainloop() method. But that's not really true. This is enough to launch a default window from the console: Google's great, but it has no truth meter. Do I inherit from Frame? Or is that a big mistake. (Both positions repeated frequently.) Do I use Tk() or...
3
3907
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 this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3662
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.