Problem resizing a window and button placement
Steve GS
Gronicus at SGA.Ninja
Sat Feb 24 22:58:00 EST 2024
So, how do I use the width value in my code?
SGA
-----Original Message-----
From: Python-list <python-list-bounces+gronicus=sga.ninja at python.org> On Behalf Of MRAB via Python-list
Sent: Saturday, February 24, 2024 10:36 PM
To: python-list at python.org
Subject: Re: Problem resizing a window and button placement
On 2024-02-25 02:51, Steve GS wrote:
> import tkinter as tk
>
> #global Ww Neither global helps
> def on_configure(*args):
> # print(args)
> #global Ww Neither global helps
> Ww = root.winfo_width()
> print("WwInside = <" + str(Ww) + ">")
>
> root = tk.Tk()
> root.bind('<Configure>', on_configure) print("WwOutside = <" + str(Ww)
> + ">")
> #NameError: name 'Ww' is not defined
> root.mainloop()
'Ww' won't exist until 'on_configure' assigns to it, and that won't happen until `mainloop` starts.
Also, 'global' works only within a function.
----8<----
import tkinter as tk
def on_configure(event):
print(f'{event.width=}, {event.height=}')
root = tk.Tk()
root.bind('<Configure>',on_configure)
root.mainloop()
----8<----
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list