我想更改ttk组合框的边框宽度和浮雕。但我只想更改1个组合框的这些属性。有没有办法让第二个组合框的边框宽度为3,浮雕为实心,就像文本框2一样?
import tkinter as tk
from tkinter import font as tkfont, filedialog, messagebox
from tkinter.ttk import Combobox
class SLS_v1(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# Setting up the root window
self.title('APP')
self.geometry("552x700")
self.resizable(False, False)
self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
self.frames["MenuPage"] = MenuPage(parent=container, controller=self)
self.frames["MenuPage"].grid(row=0, column=0, sticky="nsew")
self.show_frame("MenuPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class MenuPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
text1 = tk.Text(self, width=25, height=1)
text1.pack(pady=20)
combobox1 = tk.ttk.Combobox(self, width=25, height=2, state='readonly')
combobox1.pack(pady=20)
text2 = tk.Text(self, width=50, borderwidth=3, relief='solid', height=1)
text2.pack(pady=20)
combobox2 = tk.ttk.Combobox(self, width=50, height=5, state='readonly')
combobox2.pack(pady=20)
if __name__ == "__main__":
app = SLS_v1()
app.mainloop()
要更改ttk
对象,必须定义这样的样式。
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.style = ttk.Style(self)
self.style.theme_use("default")
然后,您可以像这样定义Combobox
的细节。
self.style.configure("K.TCombobox",
**dict(
padding = 1, arrowsize = 12,
borderwidth = 3, relief = "solid"))
完成这样的实施。
combobox2 = Combobox(self, width=50, height=5, state='readonly', style = "K.TCombobox")