2016-05-15 232 views
0

我在使用ttk的Python 3中添加了一些單選按鈕,但是它們周圍有一個白色方塊,它們與GUI其餘部分的藍色背景。用tkinter在Python 3中更改單選按鈕的背景顏色

我試過'background =','foreground =','bg =','fg =',還有其他一些東西在ttk.Radiobutton()中。它適用於標籤和其他東西...我錯過了什麼?

回答

1

ttk在其Radiobutton上不支持諸如「背景」,「前景」,「字體」等參數,但它支持樣式。 示例代碼(python 3.4):

from tkinter import * 
import tkinter.ttk as ttk 


root = Tk()       # Main window 
myColor = '#40E0D0'     # Its a light blue color 
root.configure(bg=myColor)   # Setting color of main window to myColor 

s = ttk.Style()      # Creating style element 
s.configure('Wild.TRadiobutton', # First argument is the name of style. Needs to end with: .TRadiobutton 
     background=myColor,   # Setting background to our specified color above 
     foreground='black')   # You can define colors like this also 

rb1 = ttk.Radiobutton(text = "works :)", style = 'Wild.TRadiobutton')  # Linking style with the button 

rb1.pack()       # Placing Radiobutton 

root.mainloop()      # Beginning loop 
+0

工程就像一個魅力。謝謝! –