python
  • python-3.x
  • tkinter
  • ttk
  • 2015-10-06 72 views 4 likes 
    4

    試圖改變Checkbutton的風格,我只是好奇它是否有可能改變盒子的大小?Ttk主題設置

    這是我到目前爲止。在配置部分嘗試'高度'和'寬度',但似乎沒有拿起它。

    s = ttk.Style() 
        s.theme_use('default') 
        s.configure("cbutton.TCheckbutton", foreground='#ebebeb', background='#5c5c5c', font=("arial", 14)) 
    
        s.theme_settings("default", 
         {"TCheckbutton": { 
          "configure": {"padding": 5}, 
           "map": { 
            "background": [("active", "#5C5C5C"),("!disabled", "#5C5C5C")], 
             "fieldbackground": [("!disabled", "#5C5C5C")], 
            "foreground": [("focus", "lightgray"),("!disabled", "lightgray")], "indicatorcolor": [('selected','#9ac947'),('pressed','#9ac947')] 
           } 
          } 
         }) 
    

    這可能嗎?

    謝謝!

    +0

    我不確定,但我不這麼認爲。我瀏覽過在線文檔以及「Tcl and the Tk Toolkit」第二版,我找不到任何看起來像調整複選框本身的東西。 – saulspatz

    +0

    正如您可以在[文檔] http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_checkbutton.htm#M10中閱讀的那樣,寬度和高度用於指定可用於文本的空間Checkbutton Widget。遺憾的是,Checkbutton風格無法直接擴展它。您可以通過自己創建一個新的Checkbutton小部件(例如基於Frame或Button小部件)來模擬它,並將背景圖像設置爲空或選定的checkbutton圖像以實現此目的。 – R4PH43L

    +0

    很高興知道 - 謝謝! –

    回答

    1

    在TTK指示器元件支持backgroundborderwidthindicatorcolorindicatorreliefindicatordiameterindicatormargin。這些都是使用style.configure()作爲小部件樣式的主題配置值。您可以通過更改indicatordiameter來更改Tk繪製的主題的指標元素的大小。例如:

    style = ttk.Style() 
    style.layout('Custom.Checkbutton', style.layout('TCheckbutton')) 
    style.map('Custom.Checkbutton', **style.map('TCheckbutton')) 
    style.configure('Custom.Checkbutton', **style.configure('TCheckbutton')) 
    style.configure('Custom.Checkbutton', indicatordiameter='24') 
    

    該副本的標準checkbutton風格(TCheckbutton)到一個新的風格,那麼將覆蓋自定義樣式的指標大小。

    example of a standard and customised checkbutton

    注意,對於使用的指示要素不是由Tk的主題取材,這將不被支持。例如,Windows主題的指標元素由Visual Styles API提供,其大小由系統定義的主題引擎確定。如果必須啓用這種主題自定義功能,則可以將'​​default'主題中的指示符元素導入到windows主題中,但會導致應用程序的某些部分在該UI平臺上顯得很奇怪,因爲UI外觀和感覺開始顯示不匹配。

    相關問題