简体   繁体   English

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

[英]Python 2.7: Themed “common dialog” tkinter interfaces via Ttk?

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!! Python 2.7(32位)Windows:我们正在试验Python 2.7对主题Tkinter( ttk )的简单GUI的支持,并且给人留下了非常深刻的印象! 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). 更正:换句话说, MessageBoxColorChooser常见对话框具有“丑陋”外观的Win 95风格的块状外观按钮与主题(圆角/渐变)按钮,这些按钮通常显示在XP,Vista和Windows 7下的这些常见对话框中。 (我正在所有3个平台上测试相同的,无主题的结果)。

Note: The filedialog common dialogs ( askopenfilename , askopenfilenames , asksaveasfilename , askdirectory ) are all properly themed. 注意:filedialog常用对话框( askopenfilenameaskopenfilenamesasksaveasfilenameaskdirectory )都是正确的主题。

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)? 有关将Tkinter的MessageBoxColorChooser常用对话框与操作系统主题兼容(至少在Windows XP或更高版本下)所需要的任何想法?

Your observation is mainly correct. 你的观察主要是正确的。 I do see what you are referring to in the messagebox and the colorchooser . 我确实在messageboxcolorchooser看到了你所指的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). 我建议您制作消息框的建议是使用TopLevel小部件创建自己的消息框,然后定义您需要的内容以及不同按钮的相应行为(这肯定比使用消息框更难,但如果你真的需要新的样式按钮,它会工作)。

I don't think you can hack together a solution for the colorchooser problem, however. 但是,我不认为你可以解决colorchooser问题的解决方案。

I though for a minute that perhaps Python 3.1 had fixed this problem, but sadly, I tried and that isn't the case. 我有一分钟,也许Python 3.1已经解决了这个问题,但遗憾的是,我尝试过,但事实并非如此。 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 . 获得更好看的对话框的选项是使用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. tl; dr,看来使用pyinstaller进行编译可以让你拥有当前正在运行的操作系统风格的对话框,而不是自定义样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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