【问题标题】:Personalize an awhemes theme on Tkinter ttk - Python在 Tkinter ttk 上个性化一个 awhemes 主题 - Python
【发布时间】:2022-01-19 21:23:25
【问题描述】:

我正在使用 Tkinter 开发一个 python 应用程序,并且我正在使用来自 awthemes 的 awdark 主题来使我的应用程序具有出色的外观。主题看起来非常好,但我通过查看awthemes website 意识到可以通过更改例如setHighlightColor 的图形颜色来个性化主题。似乎有很多自定义可能,但它们没有在 python 中显示具体示例,只是一些这样的代码:

package require awthemes
::themeutils::setHighlightColor awdark #007000
package require awdark

经过几次尝试,我都没有设法自定义主题,也没有在谷歌上找到任何东西,所以我请求你的帮助。

这是我的python代码:

from tkinter import *
from tkinter import ttk

root = Tk()

# Create some random widgets to see the changes
notebook = ttk.Notebook(root)
notebook.grid(row=0, column=0, sticky='nsew')
global_frame = ttk.Frame(notebook)
global_frame.grid(row=0, column=0)
notebook.add(global_frame, text="Tab1")
ttk.Radiobutton(global_frame, text="Radio 1").grid(row=0, column=0)
ttk.Radiobutton(global_frame, text="Radio 2").grid(row=0, column=1)
ttk.Progressbar(global_frame, value=75).grid(row=1, column=0, columnspan=2)

# Create a style and import the awdark theme
style = ttk.Style()
root.tk.call('lappend', 'auto_path', '/Users/marinnagy/Downloads/awthemes-10.4.0')
root.tk.call('package', 'require', 'awdark')
style.theme_use('awdark')

root.mainloop()

当前的图形界面看起来像this,如何将图形颜色更改为this picture中的绿色?

【问题讨论】:

    标签: python tkinter themes ttk


    【解决方案1】:

    试试:

    ...
    # Create a style and import the awdark theme
    style = ttk.Style()
    root.tk.call('lappend', 'auto_path', '/Users/marinnagy/Downloads/awthemes-10.4.0')
    root.tk.call('package', 'require', 'awthemes')
    root.tk.call('::themeutils::setHighlightColor', 'awdark', '#007000')
    root.tk.call('package', 'require', 'awdark')
    style.theme_use('awdark')
    ...
    

    【讨论】:

    • 谢谢,这正是我想要的。我是否必须使用新的 root.tk.call 行来调用每个修改,或者是否有更简单且重复性更低的方法,例如使用 .tcl 文件?
    • @MarinNagy 我不是 TCL 专家,所以无法提供样品.tcl。我认为您需要为每次修改执行root.tk.call()。
    • @MarinNagy 如果此答案解决了您的问题,请考虑接受它作为答案。
    猜你喜欢
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    相关资源
    最近更新 更多