Python 2.7:主题“通用对话框”通过 Ttk 的 tkinter 接口?

发布于 2024-09-28 16:01:21 字数 786 浏览 3 评论 0原文

Python 2.7(32 位)Windows:我们正在尝试使用 Python 2.7 对简单 GUI 主题 Tkinter (ttk) 的支持,并且给我们留下了深刻的印象!新主题支持似乎存在不足的一个领域是如何包装操作系统特定的常见对话框。

更正:换句话说,MessageBoxColorChooser 通用对话框具有看起来“丑陋”的 Win 95 风格的块状按钮,而不是通常显示的主题(圆形/渐变)按钮XP、Vista 和 Windows 7 下的这些常见对话框。(我正在所有 3 个平台上进行测试,结果相同,但没有主题)。

注意:filedialog 常用对话框(askopenfilenameaskopenfilenamesasksaveasfilenameaskdirectory)都有正确的主题。

import tkMessageBox as messagebox
messagebox.showinfo()

import tkColorChooser as colorchooser
color = colorchooser.askcolor( parent=root, title='Customize colors' )

关于使 Tkinter 的 MessageBoxColorChooser 通用对话框与操作系统主题兼容(至少在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-10-05 16:01:21

你的观察基本上是正确的。我确实明白您在 messageboxcolorchooser 中所指的内容。但是,我的文件对话框似乎都有适当的圆形按钮等。

我对制作消息框的建议是使用 TopLevel 小部件创建您自己的消息框,然后定义您需要的内容和不同按钮的适当行为(这肯定比仅使用消息框要困难一些,但如果您确实需要新样式的按钮,它会起作用)。

但是,我认为您无法为 colorchooser 问题找到解决方案。

我一度认为 Python 3.1 可能已经解决了这个问题,但遗憾的是,我尝试过,但事实并非如此。我想如果你需要用户选择一种颜色,按钮就必须很丑。

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.

瑕疵 2024-10-05 16:01:21

获得更好看的对话框的一个选项是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文