[Tutor] Tinkering with Tkinter

W W srilyk at gmail.com
Tue May 26 13:42:44 CEST 2009


On Mon, May 25, 2009 at 7:45 PM, Doug Reid <rnrcreid at yahoo.com> wrote:

>  The following code and it's explanation doesn't seem to work:
>
>
> 1. >>> from Tkinter import *
>
> 2. >>> tk = Tk()
>
> 3. >>> btn = Button(tk, text="click me")
>
> 4. >>> btn.pack()
>
>
>
> In line 1, we import the contents of the
> Tk module, so we can use them—the
>
> most useful of these is
> Tk, which creates a basic window to which we can then add
>
> things. After you type in line 2, that window will suddenly appear on the
> screen.
>
> In line 3, we create a new Button and assign it to the variable
> btn. The button
>
> is created by passing the
> tk object as a parameter, along with a named parameter with the words
> ‘click me’.
>
> Nothing appears on the screen after I enter line 2...I can type in the code
> in the editor and double click after saving the file and it does, but not
> from the shell, how can that be fixed or am I doing something wrong?
>

Works for me!

What is your os/python verision? Are you working from Idle? AFAIK, IDLE is
written in Tk and so it does not so much like Tkinter programs in it's
interactive shell. If you're on windows, try typing "cmd" in the run dialog
and then type "python" at the prompt, then try the example.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090526/aa810374/attachment.htm>


More information about the Tutor mailing list