On 26/02/2024 07:56, Steve GS via Python-list wrote:

> Then there is that discovery
> element: Why is my original
> idea not working? I still
> cannot pass the value back
> from the function.  What is
> different about this function
> that others would have given
> me the value?

There is nothing different, see the code below.
print() is a function like any other.
In this case it is called after you close the
window, ie after mainloop() exits.
But any other function called inside
mainloop - eg any other event handler can
also access it.

For example, if you added a button:

def printW(): print("Button Ww = ", Ww)

bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()

You would be able to print the value on demand.

>> import tkinter as tk
>>
>> Ww = None
>>
>> def on_configure(*args):
>>         global Ww
>>         Ww = root.winfo_width()
>>         print("Ww Inside =<"+str(Ww)+">")
>>
>> root = tk.Tk()
>> root.bind('<Configure>',on_configure)
>> root.mainloop()
>>
>> print("Ww Outside = <"+str(Ww)+">")

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to