Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


johnjsal at gmail

Mar 2, 2012, 5:48 PM

Post #1 of 9 (641 views)
Permalink
How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"?

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?
--
http://mail.python.org/mailman/listinfo/python-list


tjreedy at udel

Mar 2, 2012, 6:47 PM

Post #2 of 9 (614 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

On 3/2/2012 8:48 PM, John Salerno wrote:
> 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

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


ben+python at benfinney

Mar 2, 2012, 7:34 PM

Post #3 of 9 (611 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

Terry Reedy <tjreedy [at] udel> writes:

> On 3/2/2012 8:48 PM, John Salerno wrote:
> > 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.

Yes, and one mush is exactly what one gets when clobbering the namespace
with ‘from foo import *’ :-)

--
\ “We are human only to the extent that our ideas remain humane.” |
`\ —_Breakfast of Champions_, Kurt Vonnegut |
_o__) |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


johnjsal at gmail

Mar 2, 2012, 9:06 PM

Post #4 of 9 (606 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

> 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.
--
http://mail.python.org/mailman/listinfo/python-list


johnjsal at gmail

Mar 2, 2012, 9:06 PM

Post #5 of 9 (607 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

> 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.
--
http://mail.python.org/mailman/listinfo/python-list


rantingrickjohnson at gmail

Mar 4, 2012, 5:39 PM

Post #6 of 9 (607 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

On Mar 2, 11:06pm, John Salerno <johnj...@gmail.com> wrote:
> 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!

--
http://mail.python.org/mailman/listinfo/python-list


kw at codebykevin

Mar 4, 2012, 5:58 PM

Post #7 of 9 (606 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

On 3/3/12 12:06 AM, John Salerno wrote:
>> 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.

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.
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


anikom15 at gmail

Mar 4, 2012, 6:04 PM

Post #8 of 9 (605 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

On Sun, Mar 04, 2012 at 05:39:27PM -0800, Rick Johnson wrote:
> On Mar 2, 11:06pm, John Salerno <johnj...@gmail.com> wrote:
> > 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!

Make sure not to write it from scratch!
--
http://mail.python.org/mailman/listinfo/python-list


johnjsal at gmail

Mar 4, 2012, 9:53 PM

Post #9 of 9 (606 views)
Permalink
Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? [In reply to]

On Sunday, March 4, 2012 7:39:27 PM UTC-6, Rick Johnson wrote:
> On Mar 2, 11:06pm, John Salerno <johnj...@gmail.com> wrote:
> > 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!

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 attributes of the new and old widgets is a big difference. Much more streamlined.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.