Problem resizing a window and button placement

Thomas Passin list1 at tompassin.net
Sat Feb 24 08:39:55 EST 2024


On 2/24/2024 3:20 AM, Steve GS via Python-list wrote:
> Yes, I ran that elegantly
> simple code. The print
> statement reports the X, Y,
> Height and Width values.
> However, I do not see how to
> capture the width value.
> 
>   I experimented with the code
> Vwidth = rootV.winfo_width()
> and it also reports the width
> as I resize the window.
> 
> However, I cannot seem to use
> the variable Vwidth outside
> the sub routine. It is acting
> as if Vwidth is not global but
> I added that.  It is reported
> that Vwidth is not defined
> when I try to use it in my
> code.

Well, yes, in Python a variable created inside a function or method is 
local to that function unless you declare it global. That characteristic 
is called its "scope". But if you think you need it to be a global 
variable you should rethink your design. For one thing, before the next 
time you use your global variable the window size may have changed again.

Instead, it would be better to have the function that responds to the 
resize event perform the action that you want, or call another function 
that does, passing the new width to it.

Note that in most programming languages, variables have a scope.  The 
rules about those scopes vary between languages.

> 
> So close......
> SGA
> 
> -----Original Message-----
> From: Barry
> <barry at barrys-emacs.org>
> Sent: Saturday, February 24,
> 2024 3:04 AM
> To: Steve GS
> <Gronicus at sga.ninja>
> Cc: MRAB
> <python at mrabarnett.plus.com>;
> python-list at python.org
> Subject: Re: Problem resizing
> a window and button placement
> 
> 
> 
>> On 24 Feb 2024, at 04:36,
> Steve GS via Python-list
> <python-list at python.org>
> wrote:
>>
>> How do I extract the values
>> from args?
> 
> You can look up the args in
> documentation.
> You can run the example code
> MRAB provided and see what is
> printed to learn what is in
> the args.
> 
> Barry
> 
> 



More information about the Python-list mailing list