如何使 tkinter 组合框成为深色主题?
How to make tkinter combobox dark themed?
如何使 tkinter 组合框成为深色主题?我已经尝试了一点,但没有什么看起来很好。
我正在尝试做这样的事情:
如果有人能帮助我在附近建造一些东西,我将不胜感激!
我对这两个代码进行了一些试验,但这并不是我真正想要的:
style= ttk.Style()
style.theme_use('clam')
style.configure("TCombobox", fieldbackground= "orange", background= "white")
combostyle = ttk.Style()
combostyle.theme_create('combostyle', parent='alt',
settings = {'TCombobox':
{'configure':
{'selectbackground': 'blue',
'fieldbackground': 'red',
'background': 'green'
}}}
)
combostyle.theme_use('combostyle')
你很接近,但缺少两行。
style.configure("TCombobox",fieldbackground='black', background= "white",foreground='white') # changes colour of combobox itself (foreground is the text colour, background is the background colour of the arrow to drop down)
win.option_add("*TCombobox*Listbox*Background", 'black') # changes background of drop down menu of combobox
win.option_add('*TCombobox*Listbox*Foreground', 'white') # changes colour of text of options in combobox
# 'win' is the name of your window
编辑(请求我使用的完整代码):
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define the style for combobox widget
style= ttk.Style()
style.theme_use('clam')
style.configure("TCombobox",fieldbackground='black', background= "white",foreground='white')
win.option_add("*TCombobox*Listbox*Background", 'black')
win.option_add('*TCombobox*Listbox*Foreground', 'white')
# Add a label widget
label=ttk.Label(win, text= "Select a Car Model",
font= ('Aerial 11'))
label.pack(pady=30)
# Add a Combobox widget
cb= ttk.Combobox(win, width= 25, values=["Honda", "Hyundai", "Wolkswagon", "Tata", "Renault", "Ford", "Chrevolet", "Suzuki","BMW", "Mercedes"])
cb.pack()
win.mainloop()
如何使 tkinter 组合框成为深色主题?我已经尝试了一点,但没有什么看起来很好。 我正在尝试做这样的事情:
如果有人能帮助我在附近建造一些东西,我将不胜感激!
我对这两个代码进行了一些试验,但这并不是我真正想要的:
style= ttk.Style()
style.theme_use('clam')
style.configure("TCombobox", fieldbackground= "orange", background= "white")
combostyle = ttk.Style()
combostyle.theme_create('combostyle', parent='alt',
settings = {'TCombobox':
{'configure':
{'selectbackground': 'blue',
'fieldbackground': 'red',
'background': 'green'
}}}
)
combostyle.theme_use('combostyle')
你很接近,但缺少两行。
style.configure("TCombobox",fieldbackground='black', background= "white",foreground='white') # changes colour of combobox itself (foreground is the text colour, background is the background colour of the arrow to drop down)
win.option_add("*TCombobox*Listbox*Background", 'black') # changes background of drop down menu of combobox
win.option_add('*TCombobox*Listbox*Foreground', 'white') # changes colour of text of options in combobox
# 'win' is the name of your window
编辑(请求我使用的完整代码):
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define the style for combobox widget
style= ttk.Style()
style.theme_use('clam')
style.configure("TCombobox",fieldbackground='black', background= "white",foreground='white')
win.option_add("*TCombobox*Listbox*Background", 'black')
win.option_add('*TCombobox*Listbox*Foreground', 'white')
# Add a label widget
label=ttk.Label(win, text= "Select a Car Model",
font= ('Aerial 11'))
label.pack(pady=30)
# Add a Combobox widget
cb= ttk.Combobox(win, width= 25, values=["Honda", "Hyundai", "Wolkswagon", "Tata", "Renault", "Ford", "Chrevolet", "Suzuki","BMW", "Mercedes"])
cb.pack()
win.mainloop()