473,407 Members | 2,306 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,407 software developers and data experts.

Tkinter Toplevel geometry

Hi,

If a user resizes a Toplevel window, or I set a Toplevel's geometry
using the geometry() method*, is there any way to have the geometry
reset to that required for all the widgets?

I think I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
requires (ie: the user might have resized it, or a widget was
removed), use [wm geometry $toplevel].
"""
[from http://tcl.sourceforge.net/faqs/tk/]

* for instance, if I want to turn of Tkinter's automatic adjustment of
the window to fit all the widgets by doing something like
self.geometry(self.geometry()), is there any way to undo that?

Thanks,
Chris

Mar 25 '07 #1
7 6552
Chris wrote:
Hi,

If a user resizes a Toplevel window, or I set a Toplevel's geometry
using the geometry() method*, is there any way to have the geometry
reset to that required for all the widgets?

I think I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
requires (ie: the user might have resized it, or a widget was
removed), use [wm geometry $toplevel].
"""
[from http://tcl.sourceforge.net/faqs/tk/]

* for instance, if I want to turn of Tkinter's automatic adjustment of
the window to fit all the widgets by doing something like
self.geometry(self.geometry()), is there any way to undo that?

Thanks,
Chris
Hi Chris,

I think you are on to something. The equivalent of

[wm geometry $toplevel]

in Tkinter would be

sometop.geometry()

Or, equivalently,

sometop.wm_geometry()

Or, calling the underlying tcl/tk interpreter directly

sometop.tk.call('wm', 'geometry', str(sometop))

Which is redundant, but emphasizes the point: This does not resize the
widget as expected nor does it cause the window to resize upon adding
new packing slaves--at least for the X11 based Tkinter for mac via the
fink debian based package manager.

Really wish things worked according to the docs a lot of the time or
that they weren't so poorly written. Perhaps they are implying that you
must pass parameters, however they do not explain how one might generate
said parameters to get the required size to which they allude. Terribly
disappointing.

James
Mar 25 '07 #2
James Stroud wrote:
Chris wrote:
>Hi,

If a user resizes a Toplevel window, or I set a Toplevel's geometry
using the geometry() method*, is there any way to have the geometry
reset to that required for all the widgets?

I think I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
requires (ie: the user might have resized it, or a widget was
removed), use [wm geometry $toplevel].
"""
[from http://tcl.sourceforge.net/faqs/tk/]

* for instance, if I want to turn of Tkinter's automatic adjustment of
the window to fit all the widgets by doing something like
self.geometry(self.geometry()), is there any way to undo that?

Thanks,
Chris

Hi Chris,

I think you are on to something. The equivalent of

[wm geometry $toplevel]

in Tkinter would be

sometop.geometry()

Or, equivalently,

sometop.wm_geometry()

Or, calling the underlying tcl/tk interpreter directly

sometop.tk.call('wm', 'geometry', str(sometop))

Which is redundant, but emphasizes the point: This does not resize the
widget as expected nor does it cause the window to resize upon adding
new packing slaves--at least for the X11 based Tkinter for mac via the
fink debian based package manager.

Really wish things worked according to the docs a lot of the time or
that they weren't so poorly written. Perhaps they are implying that you
must pass parameters, however they do not explain how one might generate
said parameters to get the required size to which they allude. Terribly
disappointing.

James
After playing with this an inordinate amount of time, I found that one
does need to supply parameters, namely the null parameter of an empty
string. Try:

sometop.geometry('')

This repacks according to the widgets. Not quite clear from the
miserable docs, is it?

James
Mar 25 '07 #3
James Stroud wrote:
James Stroud wrote:
>Chris wrote:
>>Hi,

If a user resizes a Toplevel window, or I set a Toplevel's geometry
using the geometry() method*, is there any way to have the geometry
reset to that required for all the widgets?

I think I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
requires (ie: the user might have resized it, or a widget was
removed), use [wm geometry $toplevel].
"""
[from http://tcl.sourceforge.net/faqs/tk/]

* for instance, if I want to turn of Tkinter's automatic adjustment of
the window to fit all the widgets by doing something like
self.geometry(self.geometry()), is there any way to undo that?

Thanks,
Chris

Hi Chris,

I think you are on to something. The equivalent of

[wm geometry $toplevel]

in Tkinter would be

sometop.geometry()

Or, equivalently,

sometop.wm_geometry()

Or, calling the underlying tcl/tk interpreter directly

sometop.tk.call('wm', 'geometry', str(sometop))

Which is redundant, but emphasizes the point: This does not resize the
widget as expected nor does it cause the window to resize upon adding
new packing slaves--at least for the X11 based Tkinter for mac via the
fink debian based package manager.

Really wish things worked according to the docs a lot of the time or
that they weren't so poorly written. Perhaps they are implying that
you must pass parameters, however they do not explain how one might
generate said parameters to get the required size to which they
allude. Terribly disappointing.

James

After playing with this an inordinate amount of time, I found that one
does need to supply parameters, namely the null parameter of an empty
string. Try:

sometop.geometry('')

This repacks according to the widgets. Not quite clear from the
miserable docs, is it?

James
Now for the advanced question, how might one bind that to the
resize/maximize button of the window decorations? I'm guessing with
protocol, but its way past my bedtime.

James
Mar 25 '07 #4
After playing with this an inordinate amount of time, I found that one
does need to supply parameters, namely the null parameter of an empty
string. Try:

sometop.geometry('')

This repacks according to the widgets. Not quite clear from the
miserable docs, is it?

Wow, that does work. Thank you very much for figuring it out!

Mar 25 '07 #5
In article <11*********************@d57g2000hsg.googlegroups. com>,
Chris <ce****@gmail.comwrote:
>
>After playing with this an inordinate amount of time, I found that one
does need to supply parameters, namely the null parameter of an empty
string. Try:

sometop.geometry('')

This repacks according to the widgets. Not quite clear from the
miserable docs, is it?


Wow, that does work. Thank you very much for figuring it out!
A TRULY good way to show your thanks for help like this
is to write up what you learned at the Tkinter Wiki <URL:
http://tkinter.unpythonic.net/wiki/ >. Note:
A. You have to log in to edit pages
on this particular Wiki. If you
decide to join us, then, you'll
first need to create an account.

Read-only visitors can be anony-
mous, of course.
B. Major thanks to Jeff Epler for
maintaining the site, and, in
particular, for fighting off
recent vandalism.
Mar 25 '07 #6
In article <11**********************@l77g2000hsb.googlegroups .com>,
"Chris" <ce****@gmail.comwrote:
Hi,

If a user resizes a Toplevel window, or I set a Toplevel's geometry
using the geometry() method*, is there any way to have the geometry
reset to that required for all the widgets?

I think I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
requires (ie: the user might have resized it, or a widget was
removed), use [wm geometry $toplevel].
"""
....

I'm glad you got that figured out.

Here's a variant question that has driven me crazy...how to create a
general-purpose variation of toplevel that:
- can only be resized in one direction and auto-sizes (to fit widgets)
in the other direction?
- has a "reasonable" initial size in the resizable direction.

The first part is easy -- just use the "resizable" method. I've never
figured out a clean solution to the second question because:
- tk doesn't allow setting just X or Y size of a toplevel (the geometry
call requires both or neither)
- one can use a frame to force the resizable dimension to the desired
initial value, but to do that you either have to know in advance what
geometry manager the user is using, or make them pack their widgets into
a frame inside the toplevel

I ended up binding to the Configure event, but it's rather messy for
such a simple-seeming thing. (The really aggravating part is that perl
can do this directly because it uses C instead of tcl to talk to tk, and
tk's C interface is more flexible about setting toplevel geometry!).

-- Russell
Mar 26 '07 #7
A TRULY good way to show your thanks for help like this
is to write up what you learned at theTkinterWiki <URL:http://tkinter.unpythonic.net/wiki/>. Note:
A. You have to log in to edit pages
on this particular Wiki. If you
decide to join us, then, you'll
first need to create an account.
I'll do that, yes. I guess I should create a 'Toplevel' page and put
the information on there? Unless someone can suggest something better.

I also wonder if I should have posted this question to the tkinter-
discuss mailing list (see http://tkinter.unpythonic.net/wiki/TkinterDiscuss)
instead of to comp.lang.python. However, I wasn't aware of that list
before, and it's not linked to from the python.org 'community' page
(as far as I can see - and in fact, the python.org pages imply that
tkinter questions should be asked on comp.lang.python). I'm new to
tkinter, so it wasn't immediately clear where to get help.

Mar 27 '07 #8

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

Similar topics

2
by: Fuzzyman | last post by:
I'm working on a presentation program that needs to produce 'full screen' images. The effect will be something like a powerpoint presentation. In actual fact it's a song database with lyrics -...
2
by: k2riddim | last post by:
Hello, I'm a beginner with Python and Tkinter development. My application parse links in an html file. And I use Tkinter to implement a GUI. This GUI has a button to launch the parse treatment,...
0
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
by: python programming newb | last post by:
Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I...
3
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
2
by: jim-on-linux | last post by:
py help, The file below will run as a stand alone file. It works fine as it is. But, when I call it from another module it locks my computer, The off switch is the only salvation. This...
5
by: half.italian | last post by:
Hi all, I don't really understand how to properly use threading in my programs, however I have managed to get by so far using them improperly. Once again I have come up to what I think is...
4
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: ...
1
kaarthikeyapreyan
by: kaarthikeyapreyan | last post by:
Beginners Game- Tic-Tac-Toe My first attempt after learning Tkinter from Tkinter import * import tkFont class myApp: """ Defining The Geometry of the GUI And the variables Used In the...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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...

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.