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