[Tutor] Tkinter problem
Alan Gauld
alan.gauld at btinternet.com
Wed Jun 18 01:26:43 CEST 2008
"Arden Hall" <arhall1 at comcast.net> wrote
> I'm trying to learn to use Tkinter from "Thinking in Tkinter"
I'll make a couple of comments on the code then add a
hypothesis about the reason for your "error"
> button1 = Button(myContainer1)
> button1["text"} = "Hello, World!"
> button1[background"] = "green"
> button1.pack
Its common in Tkinter to set all the attributes in
the init method lie so:
button1 = Button(myContainer1, text="Hello, World!",background=
"green")
Or if modifying several attributes at once to use configure(),
like this:
button1.configure(text="Hello, World!",background= "green")
Its shorter and just as easy to read.
The dictionary style access tends to be reserved for single
attribute changes.
> I can execute this, but the button isn't green (or any other color I
> try) although it turns blue when I click the mouse on it. .
I think this means you are running an Aqua build of Tkinter.
It would not surprise me if such a build did not support more than
a limited subset of colours since Apple are very keen to ensure
that Aqua applications conform to their style guide. And they
like buttons to be blue or white and not much else!
I suspect that if you can find a build of Tkinter for X under
Darwin(probably via Fink) then that would behave as expected.
But not having such a build myself I can only confirm that it
works OK on my eeePC Linux box running Xandros Linux...
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list