Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The main tkinter module and its submodule ttk in Python 3 appear to contain identical widgets (i.e. Buttons, CheckButtons, etc.).

So, when creating a button, one has the freedom to either use a tkinter.Button widget or a tkinter.ttk.Button.

Do you know what is the difference between them? Why would you choose one or the other?

like image 776
multigoodverse Avatar asked Oct 24 '13 09:10

multigoodverse


People also ask

What is Tk and TTK in tkinter?

The tkinter. ttk module provides access to the Tk themed widget set, introduced in Tk 8.5. If Python has not been compiled against Tk 8.5, this module can still be accessed if Tile has been installed.

What is the difference between tkinter and tkinter?

The only difference between Tkinter and tkinter is that Tkinter was initially used with Python 2 and tkinter is used for working with Python 3 or later versions.

What are tkinter widgets in Python?

Tkinter Widgets. Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. These controls are commonly called widgets.


2 Answers

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.

like image 65
Bryan Oakley Avatar answered Oct 05 '22 11:10

Bryan Oakley


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.

like image 34
Jaidee Avatar answered Oct 05 '22 11:10

Jaidee