Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ttk styles

Reply
Thread Tools

ttk styles

 
 
Peter
Guest
Posts: n/a
 
      03-14-2011
Hi I'm struggling to get a good understanding of styles as used in
ttk. I have read the tutorial section on using styles but haven't been
able to solve this problem.

I am attempting to create a Checkbutton with the indicatoron=false
option. Using ttk the documentation is clear that you have to create a
custom style to achieve this behaviour. But the only "example" I have
been able to find on the Internet searches is written in Tcl i.e. here
is what I have found (quoted directly):

Here’s how you set it up: To achieve the effect of -indicatoron false,
create a new layout that doesn’t have an indicator:

style layout Toolbar.TCheckbutton {
Toolbutton.border -children {
Toolbutton.padding -children {
Toolbutton.label
}
}
}

Then use style map and style default to control the border appearance:

style default Toolbar.TCheckbutton \
-relief flat
style map Toolbar.TCheckbutton -relief {
disabled flat
selected sunken
pressed sunken
active raised

Hopefully somebody else in this group has "done" this and can post
their "solution"?

Thanks
Peter
 
Reply With Quote
 
 
 
 
Peter
Guest
Posts: n/a
 
      03-17-2011
No responses? Nobody with knowledge of modifying styles etc?????

On Mar 14, 2:08*pm, Peter <(E-Mail Removed)> wrote:
> Hi I'm struggling to get a good understanding of styles as used in
> ttk. I have read the tutorial section on using styles but haven't been
> able to solve this problem.
>
> I am attempting to create a Checkbutton with the indicatoron=false
> option. Using ttk the documentation is clear that you have to create a
> custom style to achieve this behaviour. But the only "example" I have
> been able to find on the Internet searches is written in Tcl i.e. here
> is what I have found (quoted directly):
>
> Here’s how you set it up: To achieve the effect of -indicatoron false,
> create a new layout that doesn’t have an indicator:
>
> style layout Toolbar.TCheckbutton {
> * * * Toolbutton.border -children {
> * * * * * *Toolbutton.padding -children {
> * * * * * * * * *Toolbutton.label
> * * * * * *}
> * * * }
>
> }
>
> Then use style map and style default to control the border appearance:
>
> style default Toolbar.TCheckbutton \
> * * *-relief flat
> style map Toolbar.TCheckbutton -relief {
> * * * disabled flat
> * * * selected sunken
> * * * pressed sunken
> * * * active raised
>
> Hopefully somebody else in this group has "done" this and can post
> their "solution"?
>
> Thanks
> Peter


 
Reply With Quote
 
 
 
 
python@bdurham.com
Guest
Posts: n/a
 
      03-17-2011
Peter,

Sorry I can't be of much help, but I share the same interest as you.

There may be some teaser info here although I can't claim to understand
the technique.
http://www.java2s.com/Open-Source/Py...losebtn.py.htm

If you have any links/documentation to share, I would love to see what
you've found so far.

Malcolm
 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      03-17-2011
Thanks for the link Malcolm, I'll have a look at it. What is
particularly interesting (at first glance), is that the author has
"mixed" Tkinter with ttk as it suited i.e. look at this line:

f1 = tkinter.Frame(nb, background="red")

If ttk was being used purely (from tkinter import *; from ttk import
*) then the "background" keyword is nolonger available/recognised and
the code would have to use ttk styles to change the colour - I find it
somewhat disappointing that the author felt this approach was
necessary as it tends to dilute the example by not keeping everything
purely ttk - modifying the style to change the background of the Frame
statements would have made it an even better example!

I will repost the answer if I can work it out using this example code
- thanks again!

Peter

On Mar 18, 9:14*am, (E-Mail Removed) wrote:
> Peter,
>
> Sorry I can't be of much help, but I share the same interest as you.
>
> There may be some teaser info here although I can't claim to understand
> the technique.http://www.java2s.com/Open-Source/Py...emo/Demo/tkint...
>
> If you have any links/documentation to share, I would love to see what
> you've found so far.
>
> Malcolm


 
Reply With Quote
 
Ethan Furman
Guest
Posts: n/a
 
      03-17-2011
Peter wrote:
> Thanks for the link Malcolm, I'll have a look at it. What is
> particularly interesting (at first glance), is that the author has
> "mixed" Tkinter with ttk as it suited i.e. look at this line:
>
> f1 = tkinter.Frame(nb, background="red")
>
> If ttk was being used purely (from tkinter import *; from ttk import
> *) then the "background" keyword is nolonger available/recognised and
> the code would have to use ttk styles to change the colour - I find it
> somewhat disappointing that the author felt this approach was
> necessary as it tends to dilute the example by not keeping everything
> purely ttk - modifying the style to change the background of the Frame
> statements would have made it an even better example!
>
> I will repost the answer if I can work it out using this example code
> - thanks again!


Another place to look for inspiration is http://tkdocs.com/

One thing to keep in mind is that not all widgets in tkinter have been
migrated to ttk (although Frame was).

~Ethan~
 
Reply With Quote
 
Ned Deily
Guest
Posts: n/a
 
      03-18-2011
In article
<(E-Mail Removed)>,
Peter <(E-Mail Removed)> wrote:

> No responses? Nobody with knowledge of modifying styles etc?????


You might also want to ask on the tkinter mailing list:

http://mail.python.org/pipermail/tkinter-discuss/

--
Ned Deily,
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      03-21-2011
Here is what I came up with - hopefully I have understood the process
correctly and therefore that the comments are correct

I am not sure I have the color of the indicator when it is (de)pressed
correct, but to my eyes the color 'snow' looks like the same color
used with a Tkinter Checkbutton with indicatoron=false.

r = Tk()

s = Style()

# create a layout that excludes the indicator element
s.layout('NoIndicator.TCheckbutton',
[('Checkbutton.border',
{'children': [('Checkbutton.padding',
{'children': [('Checkbutton.label',
{})]})]})])

# Now create(?) a 'setting' for the border appearance of the
checkbutton
s.theme_settings('default', {
'NoIndicator.TCheckbutton': {'configure': {'relief': ''}}})

# set the attributes of the 'setting' to provide the required
behaviour
s.map('NoIndicator.TCheckbutton',
relief=[('disabled', 'flat'),
('selected', 'sunken'),
('pressed', 'sunken'),
('active', 'raised'),
('!active', 'raised')],
background=[('selected', 'snow')])

button = Checkbutton(r,
text='Test',
style='NoIndicator.TCheckbutton')
button.pack()

r.mainloop()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: ttk Listbox Kevin Walzer Python 1 11-01-2011 12:00 AM
treeviewcontrol in tkinter.ttk Wolfgang Meiners Python 1 07-01-2011 06:20 AM
Python 3.2 Tkinter and TTK steven.oldner Python 1 04-28-2011 09:42 PM
Re: Python 3.2 Tkinter and TTK David Phillips Python 0 04-28-2011 09:19 PM
New Tk look (aka Ttk or Tile widgets) Robert Hicks Python 3 01-10-2008 04:04 PM



Advertisments