Ttk 样式应用到 tk class

Ttk style application onto tk class

使用 ttk bootstrap 我创建了一个主题,我希望将它应用到应用程序中。到目前为止,我得到了这段代码:

class MainAppGui(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("Interpreter")

        self.buildGUI()

        self.style = ttk.Style(self)
        self.style.configure('dark1', themes_file='..\themes\ttkbootstrap_themes_dark1.json')

    def buildGUI(self):

        self.InterBox = tk.Text(self)
        self.but1 = ttk.Button(text='ABC')

        self.InterBox.grid()
        self.but1.grid()

但样式不适用。这可能很容易,但我不知道出了什么问题。第一次尝试换风格

您必须指定 from ttkbootstrap import Style
https://github.com/israel-dryer/ttkbootstrap/blob/master/docs/tutorial.rst

#! /usr/bin/env python3
from ttkbootstrap import Style
import tkinter.ttk as ttk
import tkinter as tk
import os

##  pip3 install ttkbootstrap
##  sudo apt install fonts-symbola

##  python3 -m ttkbootstrap
##  python3 -m ttkcreator

class MainAppGui(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("Interpreter")

        cwd = os.getcwd()  ##  parent = os.path.dirname( cwd )
        filename = 'ttkbootstrap_themes_dark1.json'
        fullpath = os.path.join( cwd, 'themes', filename )

        self.style = Style( theme='dark1', themes_file=fullpath )
        self.buildGUI()

    def buildGUI(self):
        self.InterBox = tk.Text(self)
        self.but1 = ttk.Button( text='ABC' )

        self.InterBox.grid()
        self.but1.grid()

MainAppGui()
tk.mainloop()