Tkinter and classes

Justin Muir jkmuir at uniserve.com
Sun Aug 22 19:34:18 CEST 1999


Hi all.   I'm just fiddling about with Tkinter buttons and labels trying
to get the text in a Label to change when I press a button, this is
essentially what I've done:


class Helloworld:
    def __init__(self, master):
            _lblstr = StringVar()
            _lblstr.set("hello world")

            frm = Frame(master)
            frm.pack()

            but = Button(frm, text='Hello!', command=setLabel)
            but.grid(row=0)

            lbl = Label(frm, textvariable=_lblstr)
            lbl.grid(row=1)

    def setLabel(self):
            _lblstr.set("HELLO WORLD!!")

This will run, but barfs out on the callback.
Am I misunderstanding the relationship between the callback to the
namespace of the class?

Thanks!

Justin





More information about the Python-list mailing list