[Tutor] Tkinter Q's

Joseph Quigley cpu.crazy at gmail.com
Wed Jul 13 10:13:42 CEST 2005

	what's the **kw stand for, used for? What does it mean?

> Some comments ---
> You create a Frame, but you never use it.
> You've put a whole lot of code in a class, but it's not in a class method.  This
> is kinda missing the point of using classes in the first place (and it just
> flat-out wouldn't work in the majority of OO languages).
> Here's what I would do:
> class Main(Frame):
>    def __init__(self, master=None, **kw):
>        Frame.__init__(self, master, **kw)
>        showquote = Label(self, text=random.choice(quotes.quote))
>        showquote.pack()
>        # etc
> if __name__ == '__main__':
>    root = Tk()
>    main = Main(root)
>    main.pack(fill=BOTH, expand=True)
>    root.mainloop()
> ###
> Do you see what I am doing there, and why it is different from your approach?
Uh, not really, no. I'm very new to GUI. So you're saying that If I make the class actually do something (I edited and example in:
An into to Tkinter, Fredrik Lundh).


> Once you've got a label, you can change its text attribute by using its
>.config() method.
> So, you could do something like this:
>    # ...
>    showquote = Label(self, text=random.choice(quotes.quote))
>    showquote.pack()
>    def changeQuote():
>        currQuote = showquote.cget('config')  # Get the current quote
>        newQuote = random.choice(quotes.quote)
>        while newQuote == currQuote:          # Make sure the new quote differs
>            newQuote = random.choice(quotes.quote)
>        showquote.config(text=newQuote)
>    Button(self, text='Show another quote', command=changeQuote).pack()

Aaag. I'm confused... I just tried you changeQuote example with out the above stuff... didn't work. My error message:
	AttributeError: 'NoneType' object has no attribute 'config'

so I edited it a little, still didn't work (same error). I tried the  class Main(Frame) and didn't get it to work either. Do you think you could make it a little bit simpler? If you can't that's ok, I'll try to study it more.


More information about the Tutor mailing list