开发者

Making Tk look like a native Linux app

开发者 https://www.devze.com 2023-03-16 00:04 出处:网络
Browsing the TkDocs website, 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

Browsing the TkDocs website, 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).

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 开发者_如何学JAVAlike either GTK or Qt (preferably Gtk), so it would blend in to most other apps on the Linux desktop.

What about Windows Vista/7? I haven't seen any Tk screenshots on those platforms.


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.

There are partial Ttk themes that delegate to Gtk and Qt available (this presentation from 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.)


For the impatient users of a modern Linux distribution:

echo '*TkTheme: clam' >> ~/.Xresources
xrdb -merge ~/.Xresources

Then restart your Tk based app.

Here is what to expect (shown is git gui):

Making Tk look like a native Linux app

On the left is git gui started after the above command was issued. Notice how the bar changed, buttons did too.


PySolFC includes a nice, modern look and feel, which can also be used with other Tk apps.
Stephan Sokolow writes about this in his blog:

  • 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)


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.

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号