Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Tk look like a native Linux app

Tags:

linux

tk

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 like 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.

like image 220
mgiuca Avatar asked Jun 28 '11 01:06

mgiuca


2 Answers

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

like image 146
Donal Fellows Avatar answered Nov 11 '22 11:11

Donal Fellows


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

applied tk theme

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

like image 21
Elias Dorneles Avatar answered Nov 11 '22 11:11

Elias Dorneles