How do you use the widgets in tkinter.ttk if you want to "importtkinter as tk"?

J

John Salerno

According to the Python docs, the way to use tkinter.ttk is this:

from tkinter import *
from tkinter.ttk import *

But what if I don't like this import method and prefer to do:

import tkinter as tk

How then do I utilize tkinter.ttk using the same name? Or is that not possible? Will I have to use to separate names, like this:

import tkinter as tk
import tkinter.ttk as ttk

Is that the only way?
 
T

Terry Reedy

According to the Python docs, the way to use tkinter.ttk is this:

from tkinter import *
from tkinter.ttk import *

I suppose the 'advantage' of this is that it will replace tk widgets
with equivalent ttk widgets, if they exist and have the same name. I
believe one has to program them differently, however, so the replacement
cannot be transparent and one mush know anyway what gets replaced and
what not.
But what if I don't like this import method and prefer to do:

import tkinter as tk

How then do I utilize tkinter.ttk using the same name?
Or is that not possible? Will I have to use to separate names, like this:

No. One name for one object.
import tkinter as tk
import tkinter.ttk as ttk

Yes
 
J

John Salerno

I suppose the 'advantage' of this is that it will replace tk widgets
with equivalent ttk widgets, if they exist and have the same name. I
believe one has to program them differently, however, so the replacement
cannot be transparent and one mush know anyway what gets replaced and
what not.

Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal?

I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying.
 
J

John Salerno

I suppose the 'advantage' of this is that it will replace tk widgets
with equivalent ttk widgets, if they exist and have the same name. I
believe one has to program them differently, however, so the replacement
cannot be transparent and one mush know anyway what gets replaced and
what not.

Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal?

I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying.
 
R

Rick Johnson

I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying.

Your complaint is justified. The Tkinter API is a disgrace. IDLE's
source is just as bad. Luckily i have not made the jump to py3000 full-
time yet, but when i do, i think the first item on my to-do list will
be to hack this hideous tk+ttk+blah+blah into something more
friendly.

Heck, maybe i'll even release it!
 
K

Kevin Walzer

Grr, sounds like a pain if I want to use the new widgets. Does this cause conflict with someone who isn't running 8.5, or will they still see the older widgets as normal?

I'm tempted just to go back to wxPython. Two sets of widgets in Tkinter is a little annoying.

The new widgets are not a drop-in replacement for the traditional Tk
widgets. They can be used with 8.4 if the "tile" Tk extension is
installed. This is how the ttk widgets were first deployed; they didn't
enter Tk's core until 8.5.
 
W

Westley Martínez

Your complaint is justified. The Tkinter API is a disgrace. IDLE's
source is just as bad. Luckily i have not made the jump to py3000 full-
time yet, but when i do, i think the first item on my to-do list will
be to hack this hideous tk+ttk+blah+blah into something more
friendly.

Heck, maybe i'll even release it!

Make sure not to write it from scratch!
 
J

John Salerno

Your complaint is justified. The Tkinter API is a disgrace. IDLE's
source is just as bad. Luckily i have not made the jump to py3000 full-
time yet, but when i do, i think the first item on my to-do list will
be to hack this hideous tk+ttk+blah+blah into something more
friendly.

Heck, maybe i'll even release it!

Well, after reading about the themed widgets and using them a bit, they definitely seem a lot cleaner than the old ones. Just comparing the attributesof the new and old widgets is a big difference. Much more streamlined.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,630
Members
45,334
Latest member
66Zeinab9

Latest Threads

Top