Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94024 > unrolled thread

tkinter resize question

Started bynickgeovanis@gmail.com
First post2015-07-17 11:53 -0700
Last post2015-07-18 01:49 -0400
Articles 9 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  tkinter resize question nickgeovanis@gmail.com - 2015-07-17 11:53 -0700
    Re: tkinter resize question nickgeovanis@gmail.com - 2015-07-17 12:17 -0700
      Re: tkinter resize question Russell Owen <rowen@uw.edu> - 2015-07-17 12:52 -0700
        Re: tkinter resize question Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-17 13:06 -0700
        Re: tkinter resize question nickgeovanis@gmail.com - 2015-07-17 15:42 -0700
          Re: tkinter resize question Terry Reedy <tjreedy@udel.edu> - 2015-07-17 21:20 -0400
    Re: tkinter resize question Terry Reedy <tjreedy@udel.edu> - 2015-07-17 18:49 -0400
      Re: tkinter resize question nickgeovanis@gmail.com - 2015-07-17 18:31 -0700
        Re: tkinter resize question Terry Reedy <tjreedy@udel.edu> - 2015-07-18 01:49 -0400

#94024 — tkinter resize question

Fromnickgeovanis@gmail.com
Date2015-07-17 11:53 -0700
Subjecttkinter resize question
Message-ID<21c1f9fb-1af0-4c57-aeba-2c7d78b1e707@googlegroups.com>
Resizing a tkinter window which contains a frame which contains a button widget, will not change the current size of the window, frame or button as recorded in their height and width attributes (at least not if they are resizable). What is the correct way to detect their current size?

[toc] | [next] | [standalone]


#94026

Fromnickgeovanis@gmail.com
Date2015-07-17 12:17 -0700
Message-ID<dfdf0485-860f-4cfd-ad88-7476554f0291@googlegroups.com>
In reply to#94024
On Friday, July 17, 2015 at 1:53:19 PM UTC-5, nickge...@gmail.com wrote:
> Resizing a tkinter window which contains a frame which contains a button widget, will not change the current size of the window, frame or button as recorded in their height and width attributes (at least not if they are resizable). What is the correct way to detect their current size?

Ok, partially answering my own question:
The geometry of the window will change (win.geometry()), but the changes do not appear to "propagate" to the retrieved width/height of the child widgets, frames, etc. Or am I incorrect with this?

[toc] | [prev] | [next] | [standalone]


#94028

FromRussell Owen <rowen@uw.edu>
Date2015-07-17 12:52 -0700
Message-ID<mailman.657.1437162765.3674.python-list@python.org>
In reply to#94026
On 7/17/15 12:17 PM, nickgeovanis@gmail.com wrote:
> On Friday, July 17, 2015 at 1:53:19 PM UTC-5, nickge...@gmail.com wrote:
>> Resizing a tkinter window which contains a frame which contains a button widget, will not change the current size of the window, frame or button as recorded in their height and width attributes (at least not if they are resizable). What is the correct way to detect their current size?
>
> Ok, partially answering my own question:
> The geometry of the window will change (win.geometry()), but the changes do not appear to "propagate" to the retrieved width/height of the child widgets, frames, etc. Or am I incorrect with this?

I'm not seeing it. If I try the following script I see that resizing the 
widget does update frame.winfo_width() and winfo_height. (I also see 
that the requested width and height are ignored; you can omit those).

-- Russell


#!/usr/bin/env python
import Tkinter
root = Tkinter.Tk()

frame = Tkinter.Frame(root, width=100, height=50)
frame.pack(expand=True, fill="both")
def doReport(*args):
     print "frame actual    width=%s, height=%s" % (frame.winfo_width(), 
frame.winfo_height())
     print "frame requested width=%s, height=%s" % 
(frame.winfo_reqwidth(), frame.winfo_reqheight())
button = Tkinter.Button(frame, text="Report", command=doReport)
button.pack()

root.mainloop()

[toc] | [prev] | [next] | [standalone]


#94029

FromRick Johnson <rantingrickjohnson@gmail.com>
Date2015-07-17 13:06 -0700
Message-ID<c9c2685c-fdd5-46fb-bdc1-47b0e5d0c8af@googlegroups.com>
In reply to#94028
On Friday, July 17, 2015 at 2:52:56 PM UTC-5, Russell Owen wrote:

> I'm not seeing it. If I try the following script I see
> that resizing the widget does update frame.winfo_width()
> and winfo_height. (I also see that the requested width and
> height are ignored; you can omit those).

I wonder if the OP is trying to query the sizes from inside
an event handler? Hmm. But since he failed to explain the problem
coherently, and also failed to provide a code sample, i'm
not willing to exert any effort beyond that.

[toc] | [prev] | [next] | [standalone]


#94037

Fromnickgeovanis@gmail.com
Date2015-07-17 15:42 -0700
Message-ID<78761f0b-39ff-4b08-99d5-fb52e791b85b@googlegroups.com>
In reply to#94028
On Friday, July 17, 2015 at 2:52:56 PM UTC-5, Russell Owen wrote:
> On 7/17/15 12:17 PM, nickgeovanis@gmail.com wrote:
> > On Friday, July 17, 2015 at 1:53:19 PM UTC-5, nickge...@gmail.com wrote:
> >> Resizing a tkinter window which contains a frame which contains a button widget, will not change the current size of the window, frame or button as recorded in their height and width attributes (at least not if they are resizable). What is the correct way to detect their current size?
> >
> > Ok, partially answering my own question:
> > The geometry of the window will change (win.geometry()), but the changes do not appear to "propagate" to the retrieved width/height of the child widgets, frames, etc. Or am I incorrect with this?
> 
> I'm not seeing it. If I try the following script I see that resizing the 
> widget does update frame.winfo_width() and winfo_height. (I also see 
> that the requested width and height are ignored; you can omit those).
> 
> -- Russell
> 
> 
> #!/usr/bin/env python
> import Tkinter
> root = Tkinter.Tk()
> 
> frame = Tkinter.Frame(root, width=100, height=50)
> frame.pack(expand=True, fill="both")
> def doReport(*args):
>      print "frame actual    width=%s, height=%s" % (frame.winfo_width(), 
> frame.winfo_height())
>      print "frame requested width=%s, height=%s" % 
> (frame.winfo_reqwidth(), frame.winfo_reqheight())
> button = Tkinter.Button(frame, text="Report", command=doReport)
> button.pack()
> 
> root.mainloop()

So my mistake was, rather than calling frame.winfo_height() or winfo_width() as you've done, instead checking frame["width"] and frame["height"]. Which retain their original values regardless of actual size AFAICS. If you do the same on the button, I think you'll find the same (non?)issue. 

I don't think I've seen the "winfo_optioname()" construct in the python-side doc. For example Sec 25.1.6.1 "Setting Options" in the tkinter chapter of the standard python Library Reference doesn't mention it or anything syntactically similar. I'm sure the usual disclaimer "see the tcl/tk docs" applies, but this seems more than a detail to me. Thanks for your help...Nick

[toc] | [prev] | [next] | [standalone]


#94045

FromTerry Reedy <tjreedy@udel.edu>
Date2015-07-17 21:20 -0400
Message-ID<mailman.671.1437182443.3674.python-list@python.org>
In reply to#94037
On 7/17/2015 6:42 PM, nickgeovanis@gmail.com wrote:

> I don't think I've seen the "winfo_optioname()" construct in the
> python-side doc. For example Sec 25.1.6.1 "Setting Options" in the
> tkinter chapter of the standard python Library Reference doesn't
> mention it or anything syntactically similar.

The docs are incomplete.

> I'm sure the usual
> disclaimer "see the tcl/tk docs" applies, but this seems more than a
> detail to me. Thanks for your help...Nick

Better yet, bookmark this tkinter reference (which I believe is 
mentioned at the top of the doc). It is only missing stuff new in 8.6.
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
The winfo functions are included in 26 Universal widget methods.

http://effbot.org/tkinterbook/
has some worked out examples. There is also a lot on Stackoverflow, 
which has a tkinter tag.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#94039

FromTerry Reedy <tjreedy@udel.edu>
Date2015-07-17 18:49 -0400
Message-ID<mailman.666.1437173708.3674.python-list@python.org>
In reply to#94024
On 7/17/2015 2:53 PM, nickgeovanis@gmail.com wrote:
> Resizing a tkinter window which contains a frame which contains a
> button widget, will not change the current size of the window, frame
> or button as recorded in their height and width attributes (at least
> not if they are resizable).

Post the code and experiments performed that leads you to believe the above.

 > What is the correct way to detect their current size?

It is hard to fix code not posted.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#94046

Fromnickgeovanis@gmail.com
Date2015-07-17 18:31 -0700
Message-ID<114744ef-1de6-48c7-9024-727051e545a7@googlegroups.com>
In reply to#94039
On Friday, July 17, 2015 at 5:55:19 PM UTC-5, Terry Reedy wrote:
> On 7/17/2015 2:53 PM, nickgeovanis@gmail.com wrote:
> > Resizing a tkinter window which contains a frame which contains a
> > button widget, will not change the current size of the window, frame
> > or button as recorded in their height and width attributes (at least
> > not if they are resizable).
> 
> Post the code and experiments performed that leads you to believe the above.

It's really boring but here you are:

[ngeo@localhost src]$ python3
Python 3.4.2 (default, Dec 20 2014, 13:53:33) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> win=tkinter.Tk()
>>> frame=tkinter.Frame(win, bg="blue", width=200, height=200)
>>> butt1=tkinter.Button(fg="green", bg="black")
>>> frame.grid()
>>> butt1.grid()
>>> butt1["width"]
0
>>> butt1["height"]
0
>>> win["width"]
0
>>> win["height"]
0

Needless to say the button has appeared and has non-zero size.

>  > What is the correct way to detect their current size?
> 
> It is hard to fix code not posted.

Just a question from first principles: Find a widget's current size.
But the code example posted showed a working way to do the same thing.
Unfortunately requiring a function call, and not in the doc online AFAICS but....doc is doc.
 
> Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#94050

FromTerry Reedy <tjreedy@udel.edu>
Date2015-07-18 01:49 -0400
Message-ID<mailman.673.1437198597.3674.python-list@python.org>
In reply to#94046
On 7/17/2015 9:31 PM, nickgeovanis@gmail.com wrote:
> On Friday, July 17, 2015 at 5:55:19 PM UTC-5, Terry Reedy wrote:
>> On 7/17/2015 2:53 PM, nickgeovanis@gmail.com wrote:
>>> Resizing a tkinter window which contains a frame which contains a
>>> button widget, will not change the current size of the window, frame
>>> or button as recorded in their height and width attributes (at least
>>> not if they are resizable).
>>
>> Post the code and experiments performed that leads you to believe the above.
>
> It's really boring but here you are:
>
> [ngeo@localhost src]$ python3
> Python 3.4.2 (default, Dec 20 2014, 13:53:33)
> [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import tkinter
>>>> win=tkinter.Tk()
>>>> frame=tkinter.Frame(win, bg="blue", width=200, height=200)
>>>> butt1=tkinter.Button(fg="green", bg="black")
>>>> frame.grid()
>>>> butt1.grid()
>>>> butt1["width"]
> 0
>>>> butt1["height"]
> 0
>>>> win["width"]
> 0
>>>> win["height"]
> 0

I believe these configuration settings should be interpreted a 'initial 
size' (if not default) or 'desired size' or possibly min or max size, 
depending on the grid or pack settings.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web