问题
I'm working on multiple guizero projects and I'm trying to add a theme from the Python package ttkthemes (arc to be exact). I have tried to add the theme to the app widget with the following code:
from guizero import App, Text, PushButton
from ttkthemes import ThemedStyle
import tkinter.ttk as ttk
app = App(title="App")
style = ThemedStyle(app)
style.set_theme("arc")
text = Text(app, text="Text")
button = PushButton(app, text="Button")
app.display()
And it doesn't show the theme
This is what is supposed to look like before the theme
And this is what it looks like with a different theme plastik.
I think I am doing something wrong. So how do I properly add a theme to a guizero app. Thanks.
回答1:
You are not doing anything wrong. The reason why the theme does not change your guizero app is that guizero widgets are based on the basic tkinter widgets, while the theme only applies to ttk widgets.
If you want to use ttk themes, you will need to drop guizero and use ttk widgets:
from ttkthemes import ThemedStyle
import tkinter as tk
from tkinter import ttk
app = tk.Tk()
app.title('App')
style = ThemedStyle(app)
style.set_theme("arc")
tktext = tk.Label(app, text=" tk Label")
tktext.pack()
tkbutton = tk.Button(app, text="tk Button")
tkbutton.pack()
text = ttk.Label(app, text=" ttk Label")
text.pack()
button = ttk.Button(app, text="ttk Button")
button.pack()
app.geometry('200x200')
app.mainloop()
Result: with theme 'arc'
and with theme 'plastik':
来源:https://stackoverflow.com/questions/51697858/python-how-do-i-add-a-theme-from-ttkthemes-package-to-a-guizero-application