Contents:
- What is a GUI and how to work with it in Python
- Getting to Know Tkinter
- Creating a Body Mass Index Calculator
- Running Python and Importing Tkinter
- Sketching the Interface and Thinking Through the Application Logic
- Creating the Main Window and Specifying the Application Name
- Creating a Frame Widget to Control the Arrangement of Elements
- Adding Input Fields and a Button to Start Calculating the Body Mass Index body
- Get information from Entry widgets and calculate body mass index
- Evaluate the result and show it to the user
- Here is the full code without comments
- What's next?

Course with employment: "The profession of Python developer"
Find out moreDesktop applications are developed using various programming languages, such as C++, C#, C, and Python. For beginner developers, Python is the most convenient choice due to its simplicity and accessibility. There are many libraries for Python that make it easy to create graphical interfaces, making it an ideal tool for those just starting out in programming.
Tkinter is one of the libraries for creating graphical interfaces in Python, which is included in the standard package of the language. It provides developers with the ability to create applications for various operating systems, including Windows, macOS, and Linux. In this text, we will look at the main features of the Tkinter library and create a desktop application - a calculator that will help calculate a person's weight.
What is a GUI and how to work with it in Python
A graphical user interface (GUI) is a visual shell of software through which the user interacts with the computer via the keyboard and mouse. In modern operating systems, most applications use a graphical interface, which allows users to easily and intuitively perform various tasks. We encounter GUIs every day when reading articles in a browser, creating text documents in editors, or playing video games. An effective GUI ensures ease of use and increases productivity by making interaction with programs more accessible and comfortable.
The command line is the opposite of a graphical interface, allowing users to control applications using text commands. This interface is available in the macOS Terminal and the Windows Command Prompt. Using the command line allows you to perform tasks more efficiently, automate processes, and access advanced software features. Understanding the command line opens new opportunities for users and developers, improving their skills in working with operating systems.
There are four main libraries for developing graphical user interfaces (GUIs) in Python. These tools enable you to create convenient and functional interfaces for applications, providing developers with a wide range of options. The main libraries used for working with GUIs in Python include Tkinter, PyQt, wxPython, and Kivy. Each of them has unique features and is suitable for different tasks, which makes them popular among programmers. The choice of a specific library depends on the requirements of the project, the level of complexity of the interface and the preferences of the developer.
- Tkinter;
- Kivy;
- Python QT;
- wxPython.
We chose Tkinter because it does not require additional installations and provides the ability to quickly create applications with an intuitive graphical interface. Tkinter is a built-in Python library, which makes it accessible to every developer. Thanks to its simplicity and convenience, Tkinter is ideal for creating both simple and more complex user applications.
Getting to Know Tkinter
Tkinter is a convenient interface for working with the Tk library. Applications developed using Tkinter enjoy cross-platform compatibility, allowing them to run on various operating systems, such as Windows, macOS, and Linux. Due to its simplicity and efficiency, Tkinter has become a popular choice for developers creating graphical user interfaces (GUIs) in Python. Using Tkinter, you can quickly and easily create windows, buttons, text fields, and other interface elements, making it an ideal tool for creating desktop applications. Working with Tkinter can be broken down into four key steps. The first step is installing and configuring the Tkinter library, which allows you to begin working with a graphical interface in Python. The second step involves creating the main application window, which will house graphics and controls. The third step is adding widgets, such as buttons, labels, and text fields, that provide user interaction. The fourth step is event handling, which allows you to respond to user actions and ensure the application's dynamic behavior. By following these steps, you will be able to effectively develop graphical interfaces using Tkinter.

This page provides information about current events and ongoing processes. We analyze key factors influencing the situation and present up-to-date data based on actual research and observations. Understanding trends and their impact on various areas of life is crucial. We strive to provide readers with a clear understanding of current realities so they can make informed decisions. Information is updated regularly to reflect changing circumstances. Stay informed about the latest developments and analyze their impact on your area of interest.
- We include the Tkinter library using the import directive.
- We create the main application window, which will house all graphical elements.
- We add widgets—visual elements that perform specific actions.
- We create the main event loop—it includes all events that occur when the user interacts with the interface.
When working with Tkinter, widgets are key objects. These elements can be compared to HTML tags, as they allow you to create both interactive and non-interactive components, such as text labels and buttons. There are 18 types of widgets in Tkinter, but the most commonly used are the following:
- Button — buttons;
- Canvas — a "canvas" on which graphic shapes are drawn;
- Entry — a widget for creating input fields;
- Label — a container for placing text or an image;
- Menu — a widget for creating menu items.
Learning to work with widgets becomes most effective through practical application. Before moving on to implementation, let's discuss the concept of our first desktop application.
Creating a calculator for calculating body mass index
Creating a body mass index (BMI) calculator is an important task, since BMI serves as a key medical indicator for assessing a person's body weight. This indicator helps determine whether a person is overweight or obese. BMI is calculated using the following formula:
BMI = weight (kg) / (height (m))^2.
Using this calculator, users can quickly and easily assess their health, which promotes a more conscious attitude toward their weight and lifestyle. Proper understanding and use of BMI can help inform decisions about dietary or physical activity changes.
Calculation results are evaluated using a special table. Doctors have many gradations, but we use a simplified version for convenience.

Running Python and Importing Tkinter
Writing Code in Python is most effectively implemented in a specialized development environment (IDE), such as PyCharm or Visual Studio Code. These tools provide syntax highlighting and code completion, which greatly facilitates the programming process. In this article, all the code was written using Visual Studio Code, highlighting its convenience and functionality for Python developers.
The Tkinter library is included in the standard Python package, making it available for use without the need for additional installation. To begin working with the interface, simply import the Tkinter module into your project. Tkinter provides powerful tools for creating graphical user interfaces (GUIs), allowing developers to easily create windows, buttons, text fields, and other controls. Using Tkinter simplifies the process of developing GUI applications, making it accessible even for novice programmers.
Now we have the ability to use any modules from this library. This opens new horizons for development and allows us to effectively integrate functionality into our projects. With the variety of available modules, we can significantly improve the performance and expand the functionality of applications.

Check out additional materials:
Keyboard shortcuts in Visual Studio Code
Keyboard shortcuts in Visual Studio Code greatly simplify the development process, allowing you to speed up the execution of frequently used commands. Using keyboard shortcuts, you can organize your work efficiently, saving time on navigating and editing code.
Essential keyboard shortcuts include commands for opening files, navigating code, finding and replacing, and managing extensions and the terminal. For example, Ctrl + P quickly opens a file by name, and Ctrl + Shift + F activates global project search.
Furthermore, customizing your keyboard shortcuts in VS Code allows you to tailor your workspace to your needs. You can change the keyboard shortcuts for specific commands depending on your working style.
Learning keyboard shortcuts in Visual Studio Code will not only increase your productivity but also help you become a more skilled developer. Regularly practicing keyboard shortcuts will help you work faster and more efficiently, which is especially important in today's demanding software development environment.
SEO Optimization: VS Code hotkeys, shortcut keys in Visual Studio Code, productivity tips for developers, hotkey customization, commands for developers.
Sketching the interface and thinking through the application logic
Before you start coding, it's important to ask yourself a few key questions. This will help you better understand the task and simplify the development process. It's important to define the project's goals, target audience, and functional requirements. It's also worth considering the technologies and tools you'll use that will be most effective in implementing your plans. A clear understanding of these aspects will significantly improve the quality of the code and simplify its maintenance in the future.
- What data do we want to receive from the user and in what form?
- What event will trigger the BMI calculation: pressing a button, the application receiving all the necessary data, or something else?
- How will we display the result?
To accurately calculate the Body Mass Index (BMI), the user is required to enter weight and height data as integers. Weight should be entered in kilograms, and height in centimeters. The BMI calculation is performed after clicking the button, and the resulting value along with the corresponding category will be displayed in a pop-up window.
The calculator's graphical interface will be presented in schematic form.

In this article, we'll look at how to create a calculator interface and functionality using Python and the Tkinter library. Tkinter provides powerful tools for developing graphical interfaces, making it easy to create user interface applications. We'll focus on the basic components needed to implement a simple calculator, including arithmetic operations, data entry, and display of results. This project is an excellent example for learning the basics of Python programming and working with graphical interfaces.
Creating the Main Window and Specifying the Application Name
After importing the library into Python, you need to load its methods for further use. This will allow you to effectively use the library's functionality in your project. Make sure you correctly import all the necessary modules and functions to avoid errors when running your code. Each library method can offer various capabilities that will help optimize your work and improve software performance.
The first line of code loads all the Tkinter library methods, allowing you to use them without specifying their full names. In the second line, we import the messagebox method, which will be used to display a pop-up window with the results. This approach is convenient, since this method may be needed several times during the development of the interface.
Let's create a window for our application using the Tk module. Let's call it "Body Mass Index (BMI) Calculator". This application will allow users to quickly and easily calculate their BMI, which is an important indicator for assessing their health. Using Tk, we can create an intuitive interface that provides a comfortable user experience.
After running the code, it may seem like nothing is happening. This is not an error. In fact, the code executed successfully, and the application window closed. To prevent the window from closing until the user chooses to close it, we need to add the window.mainloop() function. This function initiates an event loop that allows the application to remain open and respond to user actions.
After running the code, you will see the application interface. This is the first step to interacting with the functionality we have implemented. The application screen provides the user with access to all the main functions designed to improve the user experience. Please note the controls and navigation that make working with the application intuitive and convenient.

We did not specify the window dimensions, which is why the title The app isn't fully displayed. To solve this problem, we can use the geometry method to set the necessary window parameters. This will allow the app name to be correctly displayed in the interface and improve the user experience.
The full app name is now displayed in full. This improvement makes it easier for users to identify and remember the name, which promotes more effective interaction with the app. The full name also helps with search engine optimization, as users can more easily find the app in search engines and app stores. The updated display of the title makes it more noticeable and attractive to potential users.

Creating a Frame widget to control the layout
We need to place several elements in the application window based on our sketch: two input fields with labels and one button. The key point is that the input fields should not overlap each other and go beyond the window boundaries. To achieve this, the Tkinter library can use various methods of organizing the layout of elements.
- pack - used when working with containers for elements. Allows you to position buttons, labels, or other elements inside containers.
- place - allows you to position elements by specifying exact coordinates.
- grid - places elements in the cells of a conditional grid dividing the application window.
We will use a combination of the pack and grid methods to create the interface. First, we will create a Frame widget, which will be used to place text labels, input fields, and buttons. A full description of the widget's operation is available in the documentation, but in our case, we will focus on using two properties: padx and pady. These properties will help us adjust the margins and improve the visual perception of the interface.
We will set the margins to 10 pixels both vertically and horizontally for the elements placed inside the Frame. This will ensure a neat and harmonious arrangement of components, improving visual perception and ease of interaction. Correct margins contribute to the creation of a structured interface, which is an important aspect in web design and user experience.
Adding data entry fields and a button to start the body mass index calculation
The application interface needs to integrate three types of widgets: a data entry field (Entry), text labels (Label), and a button (Button). These elements play a key role in ensuring user interaction with the application, allowing them to enter and display information, as well as initiate actions. Proper organization and use of these widgets improves the user experience and enhances the functionality of the application.
Let's start by creating labels using the Label widget. This tool allows you to easily display text messages on your interface. The Label widget is ideal for displaying headings, instructions, or any other information that needs to be conveyed to the user. With its help, you can improve the perception of your application, making it more convenient and understandable. By using the Label widget, you ensure a clear and concise presentation of data, which will positively impact user interaction with your product.
We pass two key parameters to the Label widget.
- frame - we use the Frame widget template, which already has vertical and horizontal padding configured.
- text - the text to be displayed on the screen.
The grid method is used to position the widget. We specify that the text should be placed in the cell with the coordinates "3rd row, 1st column". After running the code, we will see only one element at a given position. Using grid allows you to easily control the arrangement of elements on the page, providing flexibility in design and improving the user interface.

At the moment, the element is in the center of the window. However, it will take its correct position after adding other elements.
Let's add a second weight label, similar to the first, but specify the grid positioning on the fourth line.
Run the code and analyze the result.

Let's add fields for entering user information using the Entry widget. This interface element allows users to enter text data, making it ideal for creating forms. The Entry widget provides a convenient way to collect information from users, including their names, email addresses, and other parameters. Proper configuration and use of the Entry widget ensures a high-quality user experience and improves the overall app experience.
We used the grid method to position elements on the page. It's important that our element is positioned opposite the text label "Enter your height (in cm)." To achieve this, we place it in the same row, but in the second column. Let's run the code and evaluate the result.

Everything is completed successfully. Now you need to add a field for entering weight, following a similar principle. This field will allow users to enter weight data, which will improve the functionality and usability of the interface.
Let's analyze the result:

Add a button for Launch the body mass index (BMI) calculation using the Button widget. This button will allow users to easily initiate the BMI calculation process, providing a user-friendly interface for obtaining up-to-date information about their health.
Let's look at the final data.

In the current version of the application, all the graphical elements are implemented. Now we need to write the code that will retrieve data from the Entry widgets and calculate the body mass index (BMI). This functionality will allow users to quickly and easily obtain information about their health based on the data they enter.
Getting information from the Entry widgets and calculating the body mass index
Let's create a simple function and consider it line by line.
The function is complete, and now it is important to evaluate the calculation result. We must provide the user with a clear message so that they can evaluate the result.
Evaluating the result and showing it to the user
Let's improve our calculate_bmi function. We'll use a conditional if statement to analyze the calculated body mass index (BMI) values and use the Tkinter library's messagebox method to display the result in a popup window. This will allow the user to receive a more informative notification about their health status based on their calculated BMI.
The final step is to configure our function to run when the "Calculate BMI" button is clicked. To do this, add the command property to the Button widget. This will associate the button click event with the corresponding function, ensuring the correct BMI calculation.
Let's run the code and analyze the output. This will allow us to determine its functionality and effectiveness. Pay attention to how the code interacts with the data and what conclusions can be drawn from the results. Each run helps to better understand its behavior and optimize its operation.

The function works successfully, receiving data from the input fields and calculating the body mass index (BMI). The calculation result is displayed on the screen. Body mass index is an important indicator of a person's weight and height. Proper use of this feature allows users to quickly and easily determine their BMI, which promotes a more informed approach to managing their health and fitness.
Here's the full code without comments
What's next?
You can learn more about Tkinter and how to work with widgets in the official documentation. For more practical examples, we recommend checking out two books that will help you deepen your knowledge and skills in working with this tool.
- Python GUI Programming with Tkinter. Develop responsive and powerful GUI applications with Tkinter, Alan Moore. Tkinter GUI Programming by Example, David Love. Learn more about programming and coding in our Telegram channel. Subscribe to stay up-to-date with useful materials and updates! Read also: Writing a Messenger in C#. Part 1. Layout
- Test: Can you distinguish the Zen of Python from the philosophy of Lao Tzu?
- How to learn Python on your own and for free: algorithm

