How to access object created in Main?

Muddy Coder cosmo_general at yahoo.com
Sun Mar 29 14:12:23 EDT 2009


Hi Folks,

I need to update the text field of a Label created in Main, but can't
find a way to do it. Please take a look at my code:

from Tkinter import *

def makemenu(r)
   amenu = Menu(r)
   amenu.add_command(....., command=update_label)

def update_label():
    how to access mesg created in __main__ ?

if __name__ == '__main__':
root = Tk()
mesg = Label(root, text='foo\nbar\nfoo')
mesg.pack(expand=YES, fill=BOTH)
root.mainloop()

What I need to do is simple: when Menu (amenu) is clicked, it should
execute update_label function that is expected to update the text of
Label mesg in MAIN, with a syntax like: mesg.config(text='new text')
What I don't know is the path of accessing this object mesg. I tried
root.mesg, no good. I am confused here: since mesg is created on root
as its master, why root.mesg is not its path? Can somebody help me
out? Thanks a lot!

Muddy Coder



More information about the Python-list mailing list