本文介绍了Python - 如何将主题从 ttkthemes 包添加到 guizero 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理多个 guizero 项目,并且我正在尝试从 Python 包 ttkthemes(准确地说是圆弧)中添加一个主题.我尝试使用以下代码将主题添加到应用小部件:

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()

而且它不显示主题

这应该是主题之前的样子

This is what is supposed to look like before the theme

这就是不同主题 plastik 的样子.

And this is what it looks like with a different theme plastik.

我觉得我做错了什么.那么我如何正确地将主题添加到 guizero 应用程序.谢谢.

I think I am doing something wrong. So how do I properly add a theme to a guizero app. Thanks.

推荐答案

您没有做错任何事情.主题不会改变您的 guizero 应用程序的原因是 guizero 小部件基于基本的 tkinter 小部件,而主题仅适用于 ttk 小部件.

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.

如果您想使用 ttk 主题,则需要删除 guizero 并使用 ttk 小部件:

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()

结果:主题为'arc'

Result: with theme 'arc'

主题为plastik":

and with theme 'plastik':

这篇关于Python - 如何将主题从 ttkthemes 包添加到 guizero 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:20