[Tutor] Tkinter problem

Joe jopython at gmail.com
Mon Jun 16 03:27:42 CEST 2008


The following worked for me.

from Tkinter import *

root = Tk()

myContainer = Frame(root)
myContainer.pack()

button1 = Button(myContainer)
button1['text'] = "Hello, World!"
button1['background'] = "green"
button1.pack()

root.mainloop()



Arden Hall wrote:
> I'm trying to learn to use Tkinter from "Thinking in Tkinter" and 
> don't seem to be able to get the examples to work the way they are 
> supposed to. I have the latest version of Python on a Macbook. Here's 
> an example of the kind of problem I run into:
>
> The source code is:
>
> from Tkinter import *
>
> root = Tk()
>
> myContainer1 = Frame(root)
> myContainer.pack()
>
> button1 = Button(myContainer1)
> button1["text"} = "Hello, World!"
> button1[background"] = "green"
> button1.pack
>
> root.mainloop()
>
> 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. . Similarly, 
> I've tried to write a bit of code to create a canvas object and put a 
> rectangle in it, but I can't dimension the canvas, change its color, 
> or get the rectangle to appear. Any advice or suggestion where to look 
> for documentation would be greatly appreciated.
>
> Thanks
> Arden
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list