How to install Python ttk themes

半城伤御伤魂 提交于 2021-02-20 19:06:33

问题


This is my first post on SO, so please feel free to correct me if I'm doing anything wrong!

I am making a simple GUI for my Raspberry Pi (that runs Raspbian stretch) on Windows (because I can use PyCharm on there). I am would like to install third party themes from this site and have followed the instructions on the wiki. However, on both Windows and Raspbian, it appears to install properly without any errors, but when I check for ttk by doing this:

import tkinter.ttk
tkinter.ttk.Style().theme_names()

it still displays the default themes for the respective operating systems.

I have also looked at this SO post (How to find or install themes tkinter ttk for Python), but there are no relevant answers on there.

Edit: I now know how to use the themes in a regular tkinter/ttk GUI, but I would like to install these themes so they act like the built in ones, as I am using the appJar module that uses tkinter and ttk.

Any help and guidance would be much appreciated!


回答1:


appJar's support for ttk is still in development, but you can try overriding the default style:

from ttkthemes import ThemedStyle
app = gui(useTtk=True)
app.ttkStyle = ThemedStyle(app.topLevel)
app.ttkStyle.set_theme("plastik")

This tells appJar to use ttk, but then replaces the style appJar is using, with the style you request.




回答2:


Have you imported their package? And according to their current docs, you check for themes basically by:

from ttkthemes import themed_tk as tk   
import ttk   #(might need to add tkinter. beforehand)
window = tk.ThemedTk()
window.get_themes()

Have you tried that method?



来源:https://stackoverflow.com/questions/47251952/how-to-install-python-ttk-themes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!