简体   繁体   中英

Some ttk styles not accessible from within python script

I am trying to use a ttk style for my Tkinter gui.

When I run on the command line

>>> from ttk import *
>>> print Style().theme_names()
('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative')

which appears fine, as I want the vista style. However, when running a script with the following lines:

from ttk import *
print Style().theme_names()

the output is:

('clam', 'alt', 'default', 'classic')

and so when I try:

from ttk import *
Style().theme_use("vista")

I get:

File "test.py", line 2, in <module>
  Style().theme_use("vista")
File "/usr/lib/python2.7/lib-tk/ttk.py", line 534, in theme_use
  self.tk.call("ttk::setTheme", themename)
_tkinter.TclError: can't find package ttk::theme::vista

Not sure what it could be and I've not had much luck googling.

I'm running from within Console2 under cygwin if that makes any difference.

Thanks!

Some of the ttk themes are supported on only one platform. xpnative, winnative, and vista, for example, only work on windows. The "aqua" theme only works on OSX. The others, I think, run on any platform.

If you're running via cygwin, the version of python you're running was probably configured differently at compile time so that it think it is running on linux rather than windows. Therefore, it doesn't have access to windows themes.

My guess is you're running Linux or Mac, as Vista is a theme that pertains only to Windows. In this regard, available themes can be used in accordance to your operating system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM