如何将 awdark 主题安装到 ttk python
How to install awdark theme into ttk python
我想为我的应用安装 awdark ttk 主题,但我不知道如何安装它。我在此处 https://sourceforge.net/projects/tcl-awthemes/ 找到了源文件,但我不知道将任何文件放在哪里。任何帮助将非常感激。我在 windows 10,python3.8.3 64 位。
您可以通过执行一些 tcl 命令来加载主题:
告诉 tcl 哪里可以找到 awthemes
root.tk.eval("""
set base_theme_dir /path/to/downloaded/theme/awthemes-9.2.2/
package ifneeded awthemes 9.2.2 \
[list source [file join $base_theme_dir awthemes.tcl]]
package ifneeded colorutils 4.8 \
[list source [file join $base_theme_dir colorutils.tcl]]
package ifneeded awdark 7.7 \
[list source [file join $base_theme_dir awdark.tcl]]
# ... (you can add the other themes from the package if you want
""")
加载 awdark 主题:root.tk.call("package", "require", 'awdark')
按常规方式更改主题:style.theme_use('awdark')
这是一个完整的例子:
from tkinter import ttk
import tkinter as tk
root = tk.Tk()
style = ttk.Style(root)
# tell tcl where to find the awthemes packages
root.tk.eval("""
set base_theme_dir /path/to/downloaded/theme/awthemes-9.2.2/
package ifneeded awthemes 9.2.2 \
[list source [file join $base_theme_dir awthemes.tcl]]
package ifneeded colorutils 4.8 \
[list source [file join $base_theme_dir colorutils.tcl]]
package ifneeded awdark 7.7 \
[list source [file join $base_theme_dir awdark.tcl]]
package ifneeded awlight 7.6 \
[list source [file join $base_theme_dir awlight.tcl]]
""")
# load the awdark and awlight themes
root.tk.call("package", "require", 'awdark')
root.tk.call("package", "require", 'awlight')
print(style.theme_names())
# --> ('awlight', 'clam', 'alt', 'default', 'awdark', 'classic')
style.theme_use('awdark')
ttk.Button(root, text='Button').pack()
ttk.Checkbutton(root, text='Check Button').pack()
ttk.Radiobutton(root, text='Radio Button').pack()
root.configure(bg=style.lookup('TFrame', 'background'))
root.mainloop()
我想为我的应用安装 awdark ttk 主题,但我不知道如何安装它。我在此处 https://sourceforge.net/projects/tcl-awthemes/ 找到了源文件,但我不知道将任何文件放在哪里。任何帮助将非常感激。我在 windows 10,python3.8.3 64 位。
您可以通过执行一些 tcl 命令来加载主题:
告诉 tcl 哪里可以找到 awthemes
root.tk.eval(""" set base_theme_dir /path/to/downloaded/theme/awthemes-9.2.2/ package ifneeded awthemes 9.2.2 \ [list source [file join $base_theme_dir awthemes.tcl]] package ifneeded colorutils 4.8 \ [list source [file join $base_theme_dir colorutils.tcl]] package ifneeded awdark 7.7 \ [list source [file join $base_theme_dir awdark.tcl]] # ... (you can add the other themes from the package if you want """)
加载 awdark 主题:
root.tk.call("package", "require", 'awdark')
按常规方式更改主题:
style.theme_use('awdark')
这是一个完整的例子:
from tkinter import ttk
import tkinter as tk
root = tk.Tk()
style = ttk.Style(root)
# tell tcl where to find the awthemes packages
root.tk.eval("""
set base_theme_dir /path/to/downloaded/theme/awthemes-9.2.2/
package ifneeded awthemes 9.2.2 \
[list source [file join $base_theme_dir awthemes.tcl]]
package ifneeded colorutils 4.8 \
[list source [file join $base_theme_dir colorutils.tcl]]
package ifneeded awdark 7.7 \
[list source [file join $base_theme_dir awdark.tcl]]
package ifneeded awlight 7.6 \
[list source [file join $base_theme_dir awlight.tcl]]
""")
# load the awdark and awlight themes
root.tk.call("package", "require", 'awdark')
root.tk.call("package", "require", 'awlight')
print(style.theme_names())
# --> ('awlight', 'clam', 'alt', 'default', 'awdark', 'classic')
style.theme_use('awdark')
ttk.Button(root, text='Button').pack()
ttk.Checkbutton(root, text='Check Button').pack()
ttk.Radiobutton(root, text='Radio Button').pack()
root.configure(bg=style.lookup('TFrame', 'background'))
root.mainloop()