Python 2.7:主题“通用对话框”通过 Ttk 的 tkinter 接口?
Python 2.7(32 位)Windows:我们正在尝试使用 Python 2.7 对简单 GUI 主题 Tkinter (ttk
) 的支持,并且给我们留下了深刻的印象!新主题支持似乎存在不足的一个领域是如何包装操作系统特定的常见对话框。
更正:换句话说,MessageBox
和 ColorChooser
通用对话框具有看起来“丑陋”的 Win 95 风格的块状按钮,而不是通常显示的主题(圆形/渐变)按钮XP、Vista 和 Windows 7 下的这些常见对话框。(我正在所有 3 个平台上进行测试,结果相同,但没有主题)。
注意:filedialog 常用对话框(askopenfilename
、askopenfilenames
、asksaveasfilename
、askdirectory
)都有正确的主题。
import tkMessageBox as messagebox
messagebox.showinfo()
import tkColorChooser as colorchooser
color = colorchooser.askcolor( parent=root, title='Customize colors' )
关于使 Tkinter 的 MessageBox
和 ColorChooser
通用对话框与操作系统主题兼容(至少在 Windows XP 或更高版本下)所需的任何想法?
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 that 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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的观察基本上是正确的。我确实明白您在
messagebox
和colorchooser
中所指的内容。但是,我的文件对话框似乎都有适当的圆形按钮等。我对制作消息框的建议是使用
TopLevel
小部件创建您自己的消息框,然后定义您需要的内容和不同按钮的适当行为(这肯定比仅使用消息框要困难一些,但如果您确实需要新样式的按钮,它会起作用)。但是,我认为您无法为
colorchooser
问题找到解决方案。我一度认为 Python 3.1 可能已经解决了这个问题,但遗憾的是,我尝试过,但事实并非如此。我想如果你需要用户选择一种颜色,按钮就必须很丑。
Your observation is mainly correct. I do see what you are referring to in the
messagebox
and thecolorchooser
. 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.
获得更好看的对话框的一个选项是使用 pyinstaller 将脚本编译为可执行文件。我在此处对此进行了更彻底的解释。
tl;dr,看来使用 pyinstaller 编译允许您拥有具有当前运行操作系统样式的对话框,但不能使用自定义样式。
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.