468,241 Members | 1,403 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,241 developers. It's quick & easy.

Tkinter & Tkconstants

Hi,
I was reading through the Tkinter tutorial at
http://www.pythonware.com/library/tk...tion/index.htm ...and
it mentions that by doing,

from Tkinter import *

you have access to the constants in Tkconstants, since Tkinter imports
it automatically.

However, in the shell if I do..

from Tkinter import *

print Tkinter.HORIZONTAL

I get an error..NameError: Tkinter is not defined

any ideas? However, if I do,

import Tkconstants
print Tkconstants.HORIZTONAL

I get what i expect. but according to the tutorial i should only need
Tkinter.

Thanks.

Jul 19 '05 #1
2 5524
codecraig wrote:
from Tkinter import *

you have access to the constants in Tkconstants, since Tkinter imports
it automatically.
Yes
However, in the shell if I do..

from Tkinter import *

print Tkinter.HORIZONTAL

I get an error..NameError: Tkinter is not defined
Sure, you ask for Tkinter.HORIZONTAL. But if you directly ask for
HORIZONTAL it should work.
indeed your from statement imported the _content_ of the Tkinter module
in the global namespace not the module in itself.

It's either:
from Tkinter import *
print HORIZONTAL

or:
import Tkinter
print Tkinter.HORIZONTAL

or even:
import Tkinter
from Tkinter import *
print HORIZONTAL,Tkinter.HORIZONTAL

any ideas? I usually only use:
import OneModule

Or sometimes:
from OneModule import OneClass, OneConstant

But I usually don't import a whole module in my global namespace.
I get what i expect. but according to the tutorial i should only need
Tkinter.

You do.
Jul 19 '05 #2
nevermind, i should access it by

HORIZONTAL

not

Tkinter.HORIZONTAL

since I imported everything from Tkinter already. Thanks anyway

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Nücker | last post: by
1 post views Thread by Harlin Seritt | last post: by
9 posts views Thread by Harlin Seritt | last post: by
7 posts views Thread by Harlin Seritt | last post: by
5 posts views Thread by Ben Kovitz | last post: by
1 post views Thread by nish88 | last post: by
8 posts views Thread by Lie | last post: by
reply views Thread by nish88 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.