[Tutor] question about import statement

Bill Allen wallenpb at gmail.com
Fri Aug 27 04:16:36 CEST 2010


>
> On Thu, Aug 26, 2010 at 7:44 PM, Corey Richardson <kb1pkl at aim.com> wrote:
>
>> Why don't you try it out without the "from tkinter import ttk" statement,
>> and see if it works?
>>
>> Bill Allen wrote:
>>
>>> I was experimenting with Tk today, just trying it out.   I found this
>>> example of a very simple "hello world" button click program.  This is it.
>>>
>>> from tkinter import *
>>> from tkinter import ttk
>>>
>>> root = Tk()
>>> button = ttk.Button(root, text="Hello World").grid()
>>> root.mainloop()
>>> What I don't understand is why it is necessary to run that import
>>> statement twice.  Shouldn't import * bring everything in from tkinter?
>>>
>>>
Oops, sorry about the previous empty post.

I did try that and of course it gave an error because it was necessary.  I
just did not know why.   However, I later found an explanation on the web.
Here it is:

*from tkinter import *
from tkinter import ttk

These two lines tell Python that our program needs two modules. The first,
"tkinter", is the standard binding to Tk, which when loaded also causes the
existing Tk library on your system to be loaded. The second, "ttk", is
Python's binding to the newer "themed widgets" that were added to Tk in 8.5.
*


-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100826/62e1693d/attachment.html>


More information about the Tutor mailing list