Python GUI programming: tkinter's use of ttkbootstrap

1. Project introduction

ttkbootstrap is a tkinter-based interface beautification library. Using this tool, you can develop tkinter desktop programs similar to the front-end bootstrap style. If you know tkinter, it will be very easy to learn. If not, you only need to spend two or three days to systematically learn tkinter and then use bootstrap.

ttkbootstrap not only has a wealth of cases, but also has complete official documents, unfortunately in English. However, for programmers, as long as you use the translation software and the provided case code, you can easily get started. Then we will introduce the use of this tool.

Video explanation:

ttkbootstrap

2. Get started quickly

First of all, you must install ttkbootstrap

pip install ttkbootstrap 

Then you can create a window object, let's take a look at the official case.

insert image description here
The above cases use tkinter and ttkbootstrap to create window objects respectively. In fact, there is not much difference between the running interface. The reason is that this case is very simple. In fact, ttk.Window can set a lot of advanced properties. The related content may be followed by a video about the interpretation of the ttkbootstrap source code, which will be introduced in detail at that time. If you don't know how to choose, it is recommended to use ttk.Window to create.

The second point to note is the component using ttkbootstrap on line 10, which has some more attributes than the default component, where bootstyle is the style of the specified button. There are several button styles, of which SUCCESS is derived from the constants of ttkbootstrap.constants, and there are other styles, which can be used directly because they are exported.

When setting the bootstyle in button b2 a tuple is specified and the OUTLINE attribute is added. This property is to specify the border line. We can see an official case about its role.

Border Small Case
Border Small Case Results
insert image description here

The second button is to display the effect of the border line

3. Introduction to official documents

Style guide

Official address:https://ttkbootstrap.readthedocs.io/en/latest/styleguide/

There are many components about ttkbootstrap, and the styles are the same. If you want to create a beautiful program interface, it is best to read the documentation of these components thoroughly. Or when the style will not be added, you can know to query here

API Documentation

The interface documentation records the parameters of each component encapsulated by ttkbootstrap, and adds parameter descriptions. Although ttkbootstrap encapsulates a lot of beautiful components, it is not clear how to use it for novices. At this time, you can check the interface document to find out how the corresponding component is encapsulated, what is the function of the parameter, and that attribute should be used to achieve the desired effect.

There are rich components and functions in the interface documentation, such as time and date selection, message prompt boxes, dialog boxes, emoji images, etc. If you have requirements for the aesthetics of the program, it is highly recommended to take a look. If you just want the basic functions, there is no need to waste this time and effort.

Themes

It mainly shows some built-in themes of ttkbootstrap, and allows custom themes. It is recommended to choose a more satisfactory theme and use it directly. There is no need to use TTK Creator to create a theme of your own. You can try it yourself if you don't mind the trouble.

Gallery

All the basic cases provided by the project are stored in this. The whole project provides 11 cases, which can be said to be very rich. If you don't know how to master ttkbootstrap and use it to make a good-looking interface, it is recommended to start with these cases. Understand the case first, and then try to make a new case by yourself, it will be very fast to get started.

But novices need to pay attention, the cases here are not suitable for novices, because they are all based on object-oriented encapsulation.

Guess you like

Origin blog.csdn.net/fei347795790/article/details/123154457