如何使一个主题tkinter单选按钮下沉和提高?

2024-09-30 04:32:28 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想要达到的目标是: Radiobutton Example

所以我知道这可以用indicatoron=0在常规tkinter中完成,但这不适用于ttk或主题tkinter。有没有人知道我如何才能用我现在拥有的东西做到这一点:

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

如果不是这样的话,也很抱歉,问题都贴在这里了。这是我第一次发帖提问。你知道吗


Tags: text目标主题valuetkintervariable常规grid
1条回答
网友
1楼 · 发布于 2024-09-30 04:32:28

Question: themed tkinter Radiobutton sunken and raised?

使用以下style options隐藏indicator

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

使用style.map(...根据state更改background=颜色。你知道吗


  • STYLING OPTIONS
    根据参考资料:某些选项仅适用于特定主题。

    defaultclassicclamalt
    defaultclassicclamalt

To hide the indicator, using themeclam 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()

用Python测试:3.5-'TclVersion':8.6'TkVersion':8.6

相关问题 更多 >

    热门问题