Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21155 > unrolled thread

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

Started byJohn Salerno <johnjsal@gmail.com>
First post2012-03-02 17:48 -0800
Last post2012-03-02 21:06 -0800
Articles 9 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? John Salerno <johnjsal@gmail.com> - 2012-03-02 17:48 -0800
    Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Terry Reedy <tjreedy@udel.edu> - 2012-03-02 21:47 -0500
      Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Ben Finney <ben+python@benfinney.id.au> - 2012-03-03 14:34 +1100
      Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? John Salerno <johnjsal@gmail.com> - 2012-03-02 21:06 -0800
        Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-04 17:39 -0800
          Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Westley Martínez <anikom15@gmail.com> - 2012-03-04 18:04 -0800
          Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? John Salerno <johnjsal@gmail.com> - 2012-03-04 21:53 -0800
        Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? Kevin Walzer <kw@codebykevin.com> - 2012-03-04 20:58 -0500
      Re: How do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"? John Salerno <johnjsal@gmail.com> - 2012-03-02 21:06 -0800

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

FromJohn Salerno <johnjsal@gmail.com>
Date2012-03-02 17:48 -0800
SubjectHow do you use the widgets in tkinter.ttk if you want to "import tkinter as tk"?
Message-ID<29015333.101.1330739333318.JavaMail.geo-discussion-forums@vbbgt10>
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?

[toc] | [next] | [standalone]


#21157

FromTerry Reedy <tjreedy@udel.edu>
Date2012-03-02 21:47 -0500
Message-ID<mailman.359.1330742876.3037.python-list@python.org>
In reply to#21155
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

[toc] | [prev] | [next] | [standalone]


#21158

FromBen Finney <ben+python@benfinney.id.au>
Date2012-03-03 14:34 +1100
Message-ID<87hay6nyr8.fsf@benfinney.id.au>
In reply to#21157
Terry Reedy <tjreedy@udel.edu> 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

[toc] | [prev] | [next] | [standalone]


#21161

FromJohn Salerno <johnjsal@gmail.com>
Date2012-03-02 21:06 -0800
Message-ID<mailman.361.1330751165.3037.python-list@python.org>
In reply to#21157
> 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.

[toc] | [prev] | [next] | [standalone]


#21208

FromRick Johnson <rantingrickjohnson@gmail.com>
Date2012-03-04 17:39 -0800
Message-ID<7a170522-2fcb-4334-8d55-f71b1ffb4475@b1g2000yqb.googlegroups.com>
In reply to#21161
On Mar 2, 11:06 pm, 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!

[toc] | [prev] | [next] | [standalone]


#21212

FromWestley Martínez <anikom15@gmail.com>
Date2012-03-04 18:04 -0800
Message-ID<mailman.391.1330913096.3037.python-list@python.org>
In reply to#21208
On Sun, Mar 04, 2012 at 05:39:27PM -0800, Rick Johnson wrote:
> On Mar 2, 11:06 pm, 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!

[toc] | [prev] | [next] | [standalone]


#21222

FromJohn Salerno <johnjsal@gmail.com>
Date2012-03-04 21:53 -0800
Message-ID<16833339.2794.1330926825621.JavaMail.geo-discussion-forums@vbai14>
In reply to#21208
On Sunday, March 4, 2012 7:39:27 PM UTC-6, Rick Johnson wrote:
> On Mar 2, 11:06 pm, 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.

[toc] | [prev] | [next] | [standalone]


#21211

FromKevin Walzer <kw@codebykevin.com>
Date2012-03-04 20:58 -0500
Message-ID<jj16k0$tnk$1@dont-email.me>
In reply to#21161
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

[toc] | [prev] | [next] | [standalone]


#21162

FromJohn Salerno <johnjsal@gmail.com>
Date2012-03-02 21:06 -0800
Message-ID<409450.255.1330751162956.JavaMail.geo-discussion-forums@vbkl3>
In reply to#21157
> 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web