What is the difference between the widgets of tkinter and tkinter.ttk in Python?

Solution 1:

The widgets in tkinter are highly and easily configurable. You have almost complete control over how they look - border widths, fonts, images, colors, etc.

ttk widgets use styles to define how they look, so it takes a bit more work if you want a non-standard button. ttk widgets are also a little under-documented. Understanding the underlying theme and layout engines (layout within the widgets themselves, not pack, grid and place) is a challenge.

Generally speaking, the themed widgets will give you an application that looks more "native", but at the expense of a loss of configurability.

My advice is to use ttk widgets if you want your GUI to look a little more modern, and the tkinter widgets if you need a bit more configurability. You can use them both in the same applications.

Solution 2:

My opinion for beginners who are starting to learn Tkinter, is to use Tkinter widgets, because they're really easy to learn. But on the other hand Tkinter.ttk is a module designed to make Tkinter widgets look really perfectly, but is really hard to learn and there are no easy options there. Like there are no -fg, -bg. Perhaps, there are no new styles available in Tkinter. Style are only designed for ttk, and can be found in ttk.

And Tkinter widgets really don't look like other native platform widgets.

But ttk is nicer and smoother looking, and look like other native platforms.

So if you are making apps for your own private use, then use Tkinter and also use some ttk if needed, because ttk supports much cooler widgets that can change the look of your app.

And if you are making apps for public use, then go for both because Tkinter is needed for creating the window and some more important stuff, and for widgets go for ttk.

But honestly, I say use both because there are no conflicts between the two; just use them both to your advantage.

Honestly using ttk is a challenge! Because it has no Grid,Pack, Place and many other options that are normally available in Tkinter widgets. But wait!! Tkinter has those options! So use both! Try to make a nice app!

That is the real difference between the two: Tkinter widgets are more configurable, and ttk is more modern and it is configurable with styles which are really handy shortcuts. And Tkinter is like the core of the window and ttk is styling. Think of it like this:

Tkinter --- HTML, ttk --- CSS, Python --- JavaScript.

Solution 3:

You may want to take a look at Converting existing applications to use the Tile widgets

Also see:

Tk Widget Styling Support

As stated in this document:

Recently, other Open Source toolkits such as Qt (used by the KDE project) and GTK (used by the GIMP graphics editing software and the Gnome project) emerged as powerful and free alternatives to Motif for X-Window GUI development. The rapidly growing success of Open Source systems such as GNU/Linux helped both toolkits attract a vast community of developers, and the firm (and sometimes friendly) competition between both communities led to an explosion of new features. Thirst for freedom and customizability created the need for themeability.

The current implementation of Tk only provides native look&feel on supported platforms (Windows, X-Window, MacOS). This lack partly explains Tk's loss of mind-share, especially amongst Linux developers, where theme support is considered a "cool" or must-have feature.

While yesterday's goal of many GUIs was cross-platform visual uniformity (Qt and GTK borrowed much of their visual appearance from Windows, which borrowed earlier from NeXTStep), it is now quite common to find huge visual differences on today's desktops, even on similar systems. Screenshot contests are quite common nowadays.

...

Many Tk users may see themes support as cosmetic or of lower importance than much needed features such as megawidgets or objectification. Nevertheless, this is a critical feature to be implemented for the long-term viability of Tk. Many courses are now promoting Qt, GTK or (aarggg!) Swing in place of Motif, leaving no room for Tk. Whatever its qualities (cross-platform, performance, ease of use, internationalization and Unicode support), the lack of themeability will always be seen as one of the main reasons for not using Tk. Applications using Tk instead of GTK will look as "foreign" on pixmap-themed Linux desktop, or even on newer MacOS and Windows versions, as pre-8.0 applications were on non-X desktops.

There are some widgets (6 total) that are part of ttk, and not tkinter. there are, as stated above, some configuration items missing, like fg and bg, but this can be done with style, (introduced in tk 8.5).

Using both together, with tkinter.ttk overloading tkinter gives you the best of both worlds.

Some of the additional widgets in ttk are very useful (there are 6 that are not found in tkinter), like Notebook (tabbed windows) which I use often.

Larz60p

Solution 4:

Ttk can be more customizable, but as others have said, it takes some learning on how to build out custom styles, etc... However, the look and feel is significantly better IMO than the standard tkinter widgets.

If you want to use ttk but also want more control over colors, you can use a library like ttkbootstrap that has dozens of themes and built in color styles for each widget. There are even some non-standard widgets for meters and calendars, etc...