3

My application's GUI is Tkinter based and it is quite functional. I have been trying to use ttk to make it look more modern. I use Python 2.7 in Windows 8.1. Importing ttk goes without error and coding including ttk in the script runs without error. However, the resulting interface looks almost same as the one done only with Tkinter. This is especially true for the buttons. I tried different ttk styles and they almost look same or some worse than Tkinter-only based interface.

Tkversion in my system is 8.5. I have been using ttk that comes as part of Python 2.7 itself. I attempted installing pyttk-0.3.2 from https://pypi.python.org/pypi/pyttk but its installation always fails even after several attempts.

My questions are these:

  • Is there a known problem of Python 2.7's module ttk not playing nice under Windows 8.1?
  • Is there a possibility of error in ttk libraries even though it never results in error during import or running code with ttk?
  • Do i really need to install pyttk-0.3.2?

Also, can you please recommend a software (hopefully minimal - meaning not requiring to install too many external libraries) that is coded in Python 2.7 using Tkinter and ttk? This would help me as a point of reference on testing ttk in my computer.

Thanks in advance!

Updated with code and screenshot: (in response to @Bryan Oakley)

Here is the code I use:

from Tkinter import *
import ttk

root = Tk()
root.geometry("")
root.title("classic")

button_1 = Button(root, text='Tkinter')
button_1.grid(row=0, column=0, padx=10, pady=10)

button_2 = ttk.Button(root, text='ttk')
button_2.grid(row=0, column=1, padx=10, pady=10)

style = ttk.Style()
style.theme_use('classic')

root.mainloop()

Seven ttk theme styles are available: 'winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative'.

Here is the screenshot (updated on Apr 20) for each type:

Themes- Screenshot

Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43
  • Could you attach a screenshot that shows what your ttk and tkinter widgets look like, along with the code you used to produce it (eg: put a tkinter button and ttk button side-by-side)? It's hard to tell if your ttk widgets look incorrect, or if they are just naturally very similar to the tkinter widgets. – Bryan Oakley Apr 17 '15 at 15:09
  • @BryanOakley, I have used global ttk styles. I haven't tried customizing individual widgets so far. – Manavalan Gajapathy Apr 17 '15 at 16:18
  • @BryanOakley, I have updated my question with code and screenshot. – Manavalan Gajapathy Apr 17 '15 at 16:51
  • Ok, well, that sheds some new light. You definitely appear to have something wrong, but I don't know what. At least on windows 7, ttk buttons look much nicer. – Bryan Oakley Apr 17 '15 at 16:59
  • Have you tried using ttk without setting the style (ie: using the default without declaring you are using the default)? Have you tried using the "vista" theme? – Bryan Oakley Apr 17 '15 at 17:15
  • @BryanOakley, 'vista' theme is not even showing up in my current system. It was available in a different Windows 8.1 system with Python 2.7 but even that resulted in similar ugly interface. Is it possible to download "themes" for ttk from somewhere else? – Manavalan Gajapathy Apr 17 '15 at 17:20
  • @BryanOakley, if theme is not declared, it uses 'winnative' theme. – Manavalan Gajapathy Apr 17 '15 at 17:25
  • There aren't any repositories of themes other than what comes with ttk that I know of. This looks like a problem with your system, but I know nothing about ttk on windows 8. You might try asking on a tkinter-specific forum. – Bryan Oakley Apr 17 '15 at 17:38
  • The vista theme is based on the xpnative theme and both use the same vsapi element engine to create the UI elements. If the Visual Styles API is disabled for some reason (group policy on XP/Win7 sometimes) then these themes are disabled and will not appear. As far as I am aware on Windows 8 you should always get both the vista and xpnative themes available. We call IsThemeActive() and IsAppThemed() to check these. On WIn7 these could be disabled but I don't see any way to do that on Windows 8. – patthoyts Apr 17 '15 at 19:16
  • @patthoyts, I tried to find a way to use `IsThemeActive()` or `IsAppThemed()` but I don't know how to execute them. For what it's worth, https://msdn.microsoft.com/en-us/library/bb759809%28VS.85%29.aspx says visual styles cannot be turned off using control panel; which is what you have suggested. Could you tell me or point to a link on how to check for `IsThemeActive()` or 'IsAppThemed()`? – Manavalan Gajapathy Apr 17 '15 at 21:09
  • This was more of a comment about what is going on the the ttk C sources. However, in python you can call this with `ctypes.windll.UxTheme.IsThemeActive()` which returns 1 for me here. – patthoyts Apr 17 '15 at 21:49
  • @BryanOakley, I reinstalled Windows 8.1 and then python 2.7 for other reasons and now I get 'vista' and 'xpnative' themes. But GUI still looks ugly even with vista and xp themes (please see updated screenshot). As mentioned before, I noticed same behavior in another computer with Windows 8.1. May be Windows 8.1 is the issue? Thanks for all your help so far! – Manavalan Gajapathy Apr 20 '15 at 21:41
  • @patthoyts, thanks for the function! I reinstalled my OS and xp & vista themes are listed now. But they are not working though (see my above comment for further details). `IsThemeActive()` returns 1 for me. – Manavalan Gajapathy Apr 20 '15 at 21:43

1 Answers1

1

Your question doesn't mention it, but you should also have a "vista" theme available. Try using that theme. You might also try not setting the theme, and rely on the default (which I think should be "vista").

To address your specific questions:

Is there a known problem of Python 2.7's module ttk not playing nice under Windows 8.1?

Not that I am aware of.

Is there a possibility of error in ttk libraries even though it never results in error during import or running code with ttk?

That is highly unlikely, but apparently it's possible.

Do i really need to install pyttk-0.3.2?

No, you don't.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Thanks for your comment. If I am not wrong, you have advocated somewhere else in stackoverflow that Tkinter is not dead, and in that argument, you said interface could be effectively modernized using ttk. If that is true, why is ttk failing me in Windows? Does it mean that extensive customized ttk styling is required instead of default ttk themes available? I was excited to use as shown in https://www.youtube.com/watch?feature=player_detailpage&v=oV68QJJUXTU#t=135 but it doesn't work for me. Is that because ttk is heavily improved in Python 3.x? – Manavalan Gajapathy Apr 17 '15 at 14:58
  • @JeeYem: I don't know. Without seeing what you're seeing, I have no way of knowing if there's something wrong or not. It could be that the latest version of tkinter uses the same native widgets as ttk. In other words, I don't know tkinter is looking better than it should and thus no differences are visible, or if ttk is looking worse than it should and thus no differences are visible. – Bryan Oakley Apr 17 '15 at 15:05