[#]: subject: "Create a modern user interface with the Tkinter Python library" [#]: via: "https://opensource.com/article/23/2/user-interface-tkinter-python" [#]: author: "Patrik Dufresne https://opensource.com/users/patrik-dufresne" [#]: collector: "lkxed" [#]: translator: " " [#]: reviewer: " " [#]: publisher: " " [#]: url: " " Create a modern user interface with the Tkinter Python library ====== Python's Tkinter library isn't exactly known for its good looks. I've developed a library to help create a modern graphical user interface for Python. I spent a lot of time searching for a simple but modern GUI toolkit before developing a new library called TKVue that creates graphical interfaces for desktop applications. Through my research, I realized that there were [several different libraries][1] to create graphical interfaces. However, most involve adding new dependencies to bind with graphical libraries. For example, there's a library for Qt, another for wxWidgets, and a third for GTK. None are native to Python or entirely coded in Python. That's a problem. If you want to code a GUI with Qt, it's necessary to compile the Qt source code on each platform you want to support. I wanted to target the three leading platforms: Linux, Windows, and Mac. The big advantage of Tkinter is that it's embedded in Python. There's no need for new dependencies or to compile new libraries. Everything's already done for you. In short, it is best to use Tkinter to create something portable. ### Tkinter with a modern theme Creating a GUI with Tkinter is easy, but there's no denying that by default, it looks like a GUI from the 1980s. In addition to creating graphical interfaces that aren't very pleasing to the eye, the programming methodology is also from the 1980s: Programming the Tkinter graphical interface is not declarative. Motivated by Tkinter's portability, I was determined to use it to create a professional and modern graphical interface. My research led me to discover a whole system for modifying Tkinter's appearance using [themes][2]. Tkinter themes are similar to the CSS file of a web page. They allow you to configure the appearance of the components that make up the graphical interface by declaring new styles. The creation of these styles requires some work, but the system is flexible enough to allow the creation of a modern-looking graphical interface. This work is similar to customizing a CSS theme in web development. If you create a web page without CSS, the appearance is not modern, and a lot of work is needed to improve it. This is why CSS libraries such as bootstrap are used to speed up the creation of the graphic interface. In the Tkinter universe, there is no CSS library. Some pre-existing themes exist, but it's preferable for any project to customize the color palette to match your product branding and give it a web look-and-feel. To achieve that, the most important element in creating a modern interface with Tkinter is changing the background color and the buttons' appearance. Once properly personalized to your liking, the result is a clean and visually attractive graphical interface. Here is the "default" theme: ![Default theme][3] The "clam" theme looks like this: ![Clam theme][4] Then with my personalization: ![Personalized theme][5] **TKVue:** ``` import tkvue import tkinter.ttk as ttk tkvue.configure_tk(theme="clam") class RootDialog(tkvue.Component): template = """