ttk styles

Discussion in 'Python' started by Peter, Mar 14, 2011.

  1. Peter

    Peter Guest

    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
     
    Peter, Mar 14, 2011
    #1
    1. Advertising

  2. Peter

    Peter Guest

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

    On Mar 14, 2:08 pm, Peter <> 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
     
    Peter, Mar 17, 2011
    #2
    1. Advertising

  3. Peter

    Guest

    , Mar 17, 2011
    #3
  4. Peter

    Peter Guest

    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, 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/Python/3.1.2-Python/Demo/Demo/tkint...
    >
    > If you have any links/documentation to share, I would love to see what
    > you've found so far.
    >
    > Malcolm
     
    Peter, Mar 17, 2011
    #4
  5. Peter

    Ethan Furman Guest

    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~
     
    Ethan Furman, Mar 17, 2011
    #5
  6. Peter

    Ned Deily Guest

    Ned Deily, Mar 18, 2011
    #6
  7. Peter

    Peter Guest

    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()
     
    Peter, Mar 21, 2011
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hicks

    New Tk look (aka Ttk or Tile widgets)

    Robert Hicks, Jan 10, 2008, in forum: Python
    Replies:
    3
    Views:
    312
    Robert Hicks
    Jan 10, 2008
  2. steven.oldner

    Python 3.2 Tkinter and TTK

    steven.oldner, Apr 28, 2011, in forum: Python
    Replies:
    1
    Views:
    637
    Terry Reedy
    Apr 28, 2011
  3. David Phillips

    Re: Python 3.2 Tkinter and TTK

    David Phillips, Apr 28, 2011, in forum: Python
    Replies:
    0
    Views:
    410
    David Phillips
    Apr 28, 2011
  4. Wolfgang Meiners

    treeviewcontrol in tkinter.ttk

    Wolfgang Meiners, Jun 30, 2011, in forum: Python
    Replies:
    1
    Views:
    492
    Ned Deily
    Jul 1, 2011
  5. Kevin Walzer

    Re: ttk Listbox

    Kevin Walzer, Oct 31, 2011, in forum: Python
    Replies:
    1
    Views:
    435
    Kevin Walzer
    Nov 1, 2011
Loading...

Share This Page