hasn't fired at the time you
include the print statement in
the handler's def block, and
therefore the print function
inside your handler hasn't
invoked. It won't be invoked
until you resize the window.
Exactly....
to saving the width and height
outside your
on_configure() function,
because outside that function
you can't know if they have
been changed. There could
even have been a race
condition where you use one
but the other changes before
you get around to using it.
Aside from using it to resized
the window, is there no way to
know the last value of the
change for use in the program?
I could write the value to a
label and read it back later
in the process but that sounds
to be klugy.
for the values whenever you
need them, as you do inside
your handler.
How would that be done?
SGA
-----Original Message-----
From: Python-list
<python-list-bounces+gronicus=
***@python.org> On
Behalf Of Thomas Passin via
Python-list
Sent: Monday, February 26,
2024 8:34 AM
To: python-***@python.org
Subject: Re: Problem resizing
a window and button placement
On 2/26/2024 6:02 AM, Steve GS
Post by Steve GSAlthough your code produces
the value of Ww outside the
function, I do not see how I
can use the value of Ww unless
I close the program.
The configuration event hasn't
fired at the time you include
the print statement in the
handler's def block, and
therefore the print function
inside your handler hasn't
invoked. It won't be invoked
until you resize the window.
There is no point to saving
the width and height outside
your
on_configure() function,
because outside that function
you can't know if they have
been changed. There could
even have been a race
condition where you use one
but the other changes before
you get around to using it.
It's better just to ask tk for
the values whenever you need
them, as you do inside your
handler.
Post by Steve GSimport tkinter as tk
Ww = None # What does this
do? Why not Integer?
# These could be integers,
like 0, but that would not be
the correct # window sizes at
that point. The window is
either not constructed or it #
has some definite size that is
not zero.
Post by Steve GSglobal Ww
global WwZ
Ww =
root.winfo_width()
Post by Steve GSprint("9 Ww Inside
=<"+str(Ww)+">") # works
Post by Steve GSWwZ = Ww * 2
print("11 WwZ
Inside =<"+str(WwZ)+">") #
works
Post by Steve GSreturn(Ww) #Can I
use this?
root.bind('<Configure>',on_con
figure)
Post by Steve GSprint("15 Ww Inside1 =
<"+str(Ww)+">")
Post by Steve GS#Ww2 = int(Ww) * 2 # fails
print("17 WwZ Inside2 =
<"+str(WwZ)+">")
Post by Steve GSroot.mainloop()
Ww2 = int(Ww) * 2 #Works
but only after the program
stops
Post by Steve GSprint("21 Ww Outside2 =
<"+str(WwZ)+">") # Can I have
concentric
Post by Steve GSloops?
SGA
-----Original Message-----
From: Alan Gauld
Sent: Monday, February 26,
2024 4:04 AM
Post by Steve GSTo: Steve GS
Subject: Re: RE: Problem
resizing a window and button
placement
Post by Steve GSOn 26/02/2024 07:56, Steve
discovery
Post by Steve GSPost by Thomas Passinelement: Why is my original
idea not working? I still
cannot pass the value back
from the function. What is
different about this
function
given
Post by Steve GSThere is nothing different,
see the code below.
Post by Steve GSprint() is a function like
any other.
Post by Steve GSIn this case it is called
after you close the window, ie
after mainloop() exits.
Post by Steve GSBut any other function
called inside
Post by Steve GSmainloop - eg any other
event handler can also access
it.
Post by Steve GSFor example, if you added a
def printW(): print("Button
Ww = ", Ww)
Post by Steve GSbw = tk.Button(root,
text="Print Width",
command=printW)
Post by Steve GSbw.pack()
You would be able to print
the value on demand.
root.winfo_width()
=<"+str(Ww)+">")
root.bind('<Configure>',on_con
figure)
<"+str(Ww)+">")
Post by Steve GS--
Alan G
Author of the Learn to
Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/a
lan_gauld
Post by Steve GSFollow my photo-blog on
Flickr at:
http://www.flickr.com/photos/a
langauldphotos
--
https://mail.python.org/mailma
n/listinfo/python-list