Python 2.7 (32-bit) Windows: We're experimenting with Python 2.7's support for themed Tkinter (ttk
) for simple GUI's and have come away very impressed!! The one area where the new theme support seems to have come up short is how OS specific common dialogs are wrapped.
Corrected: In other words, the MessageBox
and ColorChooser
common dialogs have "ugly" looking Win 95 style blocky looking buttons vs. the themed (rounded/gradient) buttons th开发者_开发技巧at normally show up on these common dialogs under XP, Vista, and Windows 7. (I'm testing on all 3 platforms with identical, un-themed results).
Note: The filedialog common dialogs (askopenfilename
, askopenfilenames
, asksaveasfilename
, askdirectory
) are all properly themed.
import tkMessageBox as messagebox
messagebox.showinfo()
import tkColorChooser as colorchooser
color = colorchooser.askcolor( parent=root, title='Customize colors' )
Any ideas on what's required to get Tkinter's MessageBox
and ColorChooser
common dialogs to be OS theme compatible (at least under Windows XP or higher)?
Your observation is mainly correct. I do see what you are referring to in the messagebox
and the colorchooser
. However, my filedialogs all seem to have properly rounded buttons, etc.
My recommendation for you on making the messagebox is to create your own messagebox using the TopLevel
widget, and then define what you need on it and the appropriate behavior for the different buttons (it's definitely a bit harder than just using a messagebox, but if you really need the new style buttons, it'll work).
I don't think you can hack together a solution for the colorchooser
problem, however.
I though for a minute that perhaps Python 3.1 had fixed this problem, but sadly, I tried and that isn't the case. I suppose if you need the user to pick a color, the buttons will have to be ugly.
An option to get better looking dialog boxes is to compile your script to an executable using pyinstaller
. I explain this more thouroughly here.
tl;dr, it appears that compiling with pyinstaller
allows you to have dialog boxes with the style of the currently running OS, but not custom styles.
精彩评论