让 Tk 看起来像一个原生 Linux 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6500630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making Tk look like a native Linux app
提问by mgiuca
Browsing the TkDocswebsite, it looks like Tk has come a long way in the "native look and feel" department. But looking at some of these screenshots, it seems to be let down in Linux. If you scroll down that page, you'll see a Mac screenshot that looks exactly like Mac, a Windows XP screenshot that looks exactly like Windows XP, and a Linux screenshot that looks like ... well Windows 98 (or Windows XP with classic style).
浏览TkDocs网站,看起来 Tk 在“原生外观和感觉”部门已经走了很长一段路。但是看看这些截图中的一些,它似乎在 Linux 中失望了。如果您向下滚动该页面,您将看到一个看起来与 Mac 完全相同的 Mac 屏幕截图、一个看起来与 Windows XP 完全相同的 Windows XP 屏幕截图,以及一个看起来像……Windows 98(或带有经典版本的 Windows XP)的 Linux 屏幕截图。风格)。
I know Linux doesn't really have a "native look and feel", since every toolkit does its own styling. But I'm wondering if there is any way to style Tk so it looks like either GTK or Qt (preferably Gtk), so it would blend in to most other apps on the Linux desktop.
我知道 Linux 并没有真正的“原生外观”,因为每个工具包都有自己的样式。但我想知道是否有任何方法可以让 Tk 看起来像 GTK 或 Qt(最好是 Gtk),这样它就可以融入 Linux 桌面上的大多数其他应用程序。
What about Windows Vista/7? I haven't seen any Tk screenshots on those platforms.
Windows Vista/7 怎么样?我还没有在这些平台上看到任何 Tk 截图。
采纳答案by Donal Fellows
Tk has basically two sets of widgets, the classic widgets and the themed widgets. The classic widgets are default because of the need to support old applications, but new code should use the themed widgets. (They can't be overloaded because they work in quite different ways, and there's a lot of code out there that depends on the old classic way. Alas.) With the right theme, the themed widgets (typically referred to as Ttk) look native and behave natively on Windows and OSX.
Tk 基本上有两组小部件,经典小部件和主题小部件。由于需要支持旧应用程序,经典小部件是默认的,但新代码应该使用主题小部件。(它们不能被重载,因为它们以完全不同的方式工作,并且有很多代码依赖于旧的经典方式。唉。)有了正确的主题,主题小部件(通常称为 Ttk)看起来本机并在 Windows 和 OSX 上以本机方式运行。
There are partial Ttk themes that delegate to Gtk and Qt available (this presentationfrom last year shows them in action) but they're partial, in large part because of the poor quality of the themes (Gtk/Qt themes, not Ttk themes; this is confusing!) in typical use with those toolkits. The major problem is apparently in the reporting of metrics, which often seems to be wrong (resulting in widgets getting the wrong size or visual elements being put in the wrong place); I understand from talking to the author of that paper that a significant fraction of themes only happen to work with Gtk/Qt, but cannot verify this from personal experience. (I'm on OSX so I use Ttk's direct native support.)
有部分 Ttk 主题可以委托给 Gtk 和 Qt(去年的这个演讲展示了它们的实际效果)但它们是部分的,在很大程度上是因为主题的质量很差(Gtk/Qt 主题,而不是 Ttk 主题;这令人困惑!)通常与这些工具包一起使用。主要问题显然在于指标的报告,这通常似乎是错误的(导致小部件的大小错误或视觉元素放置在错误的位置);我从与那篇论文的作者交谈中了解到,很大一部分主题仅适用于 Gtk/Qt,但无法从个人经验中验证这一点。(我在 OSX 上,所以我使用 Ttk 的直接本机支持。)
回答by Corey Richardson
Just from what I've heard in Python's main mailing list from time to time, Themed TK (TTK) widgets are themable and can either mimic native widgets or do their own thing and look good. See http://www.tkdocs.com/tutorial/styles.html.
只是从我不时在 Python 的主要邮件列表中听到的内容来看,主题 TK (TTK) 小部件是可主题化的,可以模仿原生小部件,也可以做自己的事情并且看起来不错。请参阅http://www.tkdocs.com/tutorial/styles.html。
From experience, Tk (at least through Python) looks like crap. I pulled up a test for you on windows 7: http://sadpanda.us/images/542945-LNUGO0F.jpg. Not really a looker by default!
根据经验,Tk(至少通过 Python)看起来很垃圾。我在 Windows 7 上为你做了一个测试:http: //sadpanda.us/images/542945-LNUGO0F.jpg。默认情况下不是真正的旁观者!
回答by f3lix
PySolFCincludes a nice, modern look and feel, which can also be used with other Tk apps.
Stephan Sokolowwrites about this in his blog:
PySolFC包括漂亮、现代的外观和感觉,也可以与其他 Tk 应用程序一起使用。
Stephan Sokolow在他的博客中写道:
- Making Tk applications a bit less ugly(how to change the Tk theme)
- Installing a new Ttk/Tile theme(how to use PySolFC's theme)
- 使 Tk 应用程序不那么难看(如何更改 Tk 主题)
- 安装新的 Ttk/Tile 主题(如何使用 PySolFC 的主题)
回答by Elias Dorneles
For the impatient users of a modern Linux distribution:
对于不耐烦的现代 Linux 发行版用户:
echo '*TkTheme: clam' >> ~/.Xresources
xrdb -merge ~/.Xresources
Then restart your Tk based app.
然后重新启动基于 Tk 的应用程序。
Here is what to expect (shown is git gui):
这是预期的内容(显示的是 git gui):
On the left is git gui started after the above command was issued. Notice how the bar changed, buttons did too.
左边是执行上述命令后启动的git gui。注意栏是如何变化的,按钮也是如此。