1

So what I want to achieve is something like this: Radiobutton Example

So I know this can be done in regular tkinter with indicatoron=0 but this does not work with ttk or themed tkinter. Does anyone know how I would be able to achieve this with what I currently have:

radiobutton1 = ttk.Radiobutton(labelFrameDegreesIncrement, text='1°', variable=varDegreeIncrement, value=1).grid(row=0, column=0)

Also sorry if this isn't the form questions are posted here. This is my first time posting a question.

Community
  • 1
  • 1
Brian Shen
  • 21
  • 8
  • Try [STYLING OPTIONS `indicatorrelief`](http://www.tcl.tk/man/tcl8.6/TkCmd/ttk_radiobutton.htm). Read also [AttributeError: NoneType object has no attribute ...](https://stackoverflow.com/a/1101765/7414759) – stovfl Nov 16 '19 at 15:05
  • So I tried `indicatorrelief` but it came back with `_tkinter.TclError: unknown option "-indicatorrelief"`. Also I'm not sure how `ttk.style` is used according the documentation you gave. It seems that the syntax there is a lot different than what I'm used to. – Brian Shen Nov 16 '19 at 15:15
  • With `ttk` you have to use `ttk.Style()` and `ttk.Radiobutton(..., style='MyRadioButtonStyle')`. See for ref [`tkinter.Style`](https://stackoverflow.com/a/58201652/7414759) – stovfl Nov 16 '19 at 15:20
  • Does this answer your question? [Tkinter radiobutton indicatoron not recognised](https://stackoverflow.com/questions/24247133/tkinter-radiobutton-indicatoron-not-recognised) – stovfl Nov 16 '19 at 15:26

1 Answers1

3

Question: themed tkinter Radiobutton sunken and raised?

Use the following style options to hide the indicator:

indicatorrelief=tk.FLAT,
indicatormargin=-1,
indicatordiameter=-1,

Use style.map(... to change the background= color according to the state.


  • STYLING OPTIONS
    According to the reference: Some options are only available for specific themes.

    default classic  clam  alt
    default          classic          clam                    alt

To hide the indicator, using theme clam or alt, you need: indicatormargin=-10


import tkinter as tk
import tkinter.ttk as ttk

class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('ttk')
        style = ttk.Style(self)
        # style.theme_use('alt')  # 'aqua', 'step', 'clam', 'alt', 'default', 'classic'

        style.configure('IndicatorOff.TRadiobutton',
                        indicatorrelief=tk.FLAT,
                        indicatormargin=-1,
                        indicatordiameter=-1,
                        relief=tk.RAISED,
                        focusthickness=0, highlightthickness=0, padding=5)

        style.map('IndicatorOff.TRadiobutton',
                  background=[('selected', 'white'), ('active', '#ececec')])

        MODES = [("Monochrome", "1"),
                 ("Grayscale", "L"),
                 ("True color", "RGB"),
                 ("Color separation", "CMYK")]

        v = tk.StringVar(self, "L")  # initialize

        for text, mode in MODES:
            ttk.Radiobutton(self, text=text, variable=v, value=mode, width=15,
                            style='IndicatorOff.TRadiobutton').grid()


if __name__ == "__main__":
    App().mainloop()

Tested with Python: 3.5 - 'TclVersion': 8.6 'TkVersion': 8.6

stovfl
  • 14,998
  • 7
  • 24
  • 51