簡體   English   中英

如何使主題 tkinter 單選按鈕凹陷和凸起?

[英]How to make a themed tkinter Radiobutton sunken and raised?

所以我想要實現的是這樣的: 單選按鈕示例

所以我知道這可以在通常的 tkinter 中使用indicatoron=0來完成,但這不適用於 ttk 或主題 tkinter。 有誰知道我將如何用我目前擁有的東西來實現這一目標:

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

如果這不是此處發布的表格問題,也很抱歉。 這是我第一次發布問題。

問題:主題 tkinter 單選按鈕凹陷和凸起?

使用以下style options隱藏indicator

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

使用style.map(...根據state更改background=顏色。


  • 樣式選項
    根據參考:某些選項僅適用於特定主題。

    默認 經典的 蛤 alt
    default classic clam alt

要隱藏indicator ,使用theme clamalt ,您需要: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM