简体   繁体   English

如何更改1 ttk combobox的borderwidth和relief

[英]How to change the borderwidth and relief of 1 ttk combobox

I am wanting to change the borderwidth and relief of a ttk combobox.我想更改 ttk combobox 的边框宽度和浮雕。 But I only want to change these attributes for 1 combobox.但我只想为 1 combobox 更改这些属性。 Is there a way to make the second combobox have a borderwidth of 3 and a relief of solid, like the text box 2?有没有办法使第二个 combobox 的边框宽度为 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()

To change ttk objects you must define the style like this.要更改ttk对象,您必须像这样定义样式。

def __init__(self, *args, **kwargs):
    tk.Tk.__init__(self, *args, **kwargs)

    self.style = ttk.Style(self)
    self.style.theme_use("default")

Then you can define specifics for your Combobox like this.然后你可以像这样为你的Combobox定义细节。

self.style.configure("K.TCombobox",
                     **dict(
                         padding = 1, arrowsize = 12,
                         borderwidth = 3, relief = "solid"))

Complete implementation like this.像这样完成实现。

combobox2 = Combobox(self, width=50, height=5, state='readonly', style = "K.TCombobox")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM