Problem resizing a window and button placement

Steve GS Gronicus at SGA.Ninja
Sat Feb 24 19:33:52 EST 2024


"Well, yes, in Python a
variable created inside a
function or method is local to
that function unless you
declare it global."

Yes, I knew that. I tried to
global it both before the
function call and within it.
Same for when I created the
variable. If I try to use it
in the rest of the code, it
keeps coming up as not
declared.  In other functions,
I can 'return' the variable
but that apparently would not
work for this function.

Is this type of function any
different that that which I
have been using?

SGA

-----Original Message-----
From: Python-list
<python-list-bounces+gronicus=
sga.ninja at python.org> On
Behalf Of Thomas Passin via
Python-list
Sent: Saturday, February 24,
2024 8:40 AM
To: python-list at python.org
Subject: Re: Problem resizing
a window and button placement

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
> 
> 

--
https://mail.python.org/mailma
n/listinfo/python-list



More information about the Python-list mailing list