Python 如何更改tkinter中combobox的背景色?
我正在尝试将tkinter中combobox的背景色更改为红色。但我不能这样做,请帮忙。 这是我的密码 '''Python 如何更改tkinter中combobox的背景色?,python,tkinter,colors,combobox,background,Python,Tkinter,Colors,Combobox,Background,我正在尝试将tkinter中combobox的背景色更改为红色。但我不能这样做,请帮忙。 这是我的密码 ''' #代码 style=ttk.style() style.map('TCombobox',fieldbackground=[('readonly','red')) style.map('TCombobox',selectbackground=[('readonly','red')) style.map('TCombobox',select前台=[('readonly','white'))
#代码
style=ttk.style()
style.map('TCombobox',fieldbackground=[('readonly','red'))
style.map('TCombobox',selectbackground=[('readonly','red'))
style.map('TCombobox',select前台=[('readonly','white'))
n=tk.StringVar(值=下载选项[0])
n、 设置(下载\u选项[0])
youtubeChoicesLabel=ttk.Combobox(root,font=font,justify='center',textvariable=n,values=download\u选项)
youtubeChoicesLabel[“状态”]=“只读”
youtubeChoicesLabel.bind(“”)
youtubeChoicesLabel.current(0)
#youtubeChoicesLabel[“selectbackground”]=“ff0000”
#youtubeChoicesLabel[“前景”]=“000000”
youtubeChoicesLabel.pack(侧=顶部,pady=20)
“”“问题在于您使用的主题。有些主题不允许您更改某些功能。例如,如果使用“vista”主题,则不能更改按钮或组合框的背景色 您需要将主题更改为允许您更改按钮或组合框的背景色等功能的主题。您可以更改主题,如图所示:
style.theme_use("default")
您不必使用“默认”主题,只需使用一个允许您更改组合框背景颜色的主题即可。我使用“默认”是因为我知道它可以让你改变背景颜色
style.theme_use("default")