How to Create GUI Window in Python TKinter

In this Python TKinter article we are going to learn about How to Create GUI Window in Python TKinter, Python is very powerful programming language, and It ships with the built-in tkinter module. In only few lines of code (four, to be precise) we can build our first Python GUI, the IDE that we are using is Pycharm Community Edition IDE, first of all let’s talk about Python TKinter GUI Library, when it comes to GUI Development with Python you have different options, one of them are TKinter module.

 

 

What is Python TKinter ?

Python Tkinter is standard GUI (Graphical User Interface) library that comes with Python. it is builtin library and can be used to create desktop applications with graphical user interfaces.

Tkinter provides different widgets or graphical elements, including buttons, labels, text boxes, menus, canvas and many more, that you can use to create interactive GUIs. you can customize these widgets by changing their properties, such as size, color, font and style.

Tkinter is cross platform GUI toolkit, which means that the GUI applications you create with it can run on different operating systems, such as Windows, macOS and Linux. it is also easy to learn and use and this makes it popular choice for beginners who want to create simple desktop applications, TKinter is already packaged with Python, so you don’t need to install that.

 

 

Key Features of Python TKinter

As we already have mentioned that Python Tkinter is standard GUI (Graphical User Interface) library for creating desktop applications with consistent look and feel across multiple operating systems. these are some of the key features of Python Tkinter:

  1. Simple and Easy-to-Use: Python Tkinter is easy to learn and use, even for beginners. the simple syntax and widget hierarchy make it easy to create GUI applications quickly and easily.
  2. Cross-Platform: Tkinter is available on many platforms, including Windows, Mac OS X and Linux and this makes it popular choice for cross platform GUI development.
  3. Standard Library: Tkinter is standard Python library, which means it is included with every Python installation. there is no need to install any additional software or libraries to use Tkinter.
  4. Wide Range of Widgets: Tkinter provides different widgets, including buttons, labels, text boxes, radio buttons, check boxes, list boxes, drop-down menus, scroll bars, canvas and many more. and this makes it easy to create complex GUI applications with different UI elements.
  5. Customizable Look and Feel: Tkinter allows you to customize the look and feel of your application by changing the color, font and style of the widgets. you can also create custom widgets and themes to match your application’s branding.
  6. Event-Driven Programming: Tkinter is based on the event driven programming model, where the application waits for events to occur and then responds to them. this makes it easy to handle user interactions and create responsive applications.
  7. Integration with Other Libraries: Tkinter can be integrated with other Python libraries, such as Matplotlib for data visualization, and PIL (Python Imaging Library) for image processing. this makes it easy to extend the functionality of your application beyond the standard widgets.

 

We can say that Python Tkinter is powerful GUI library that offers simple and easy interface for creating cross platform gui desktop applications with different widgets and customization options.

 

 

 

This is the complete code for creating of Window in Python TKinter

So at the top first we have imported tkinter, after that we have created a Root class this Root class extends from TK a built in class in TKinter module. after that we have created title, window size and also icon for our Window. at the end we create the object of our Root class and we start our loop for the GUI.The event loop ends when the user clicks the red X button or a widget that we have programmed to end our GUI. When the event loop ends, our GUI also ends.

 

 

Run you code and you will see this output

How to Create GUI Window in Python TKinter
How to Create GUI Window in Python TKinter

 

 

 

 

 

 

 

 

Now let’s create complex example and we want to add some widgets in out Python TKinter GUI Window.

This example creates custom Python Tkinter widget called ExampleGUI that extends tk.Frame class. widget contains menu bar with two menus (File and Help), label, text box and three buttons.

To create menu bar, example creates two menus (File and Help) using the tk.Menu class and adds commands to them using the add_command method. menu bar is then added to the root window using the config method.

label and text box are created using the tk.Label and tk.Text classes, respectively. label has  custom font size of 20 and the text box has a height of 10 and a width of 50.

and finally three buttons are created using the tk.Button class and placed in tk.Frame using the pack method. each button has custom command function that prints a message to the console when clicked. note that the widget is first packed

 

 

 

 

Run your code and this is the output

How to Create GUI Window in Python TKinter
How to Create GUI Window in Python TKinter

 

 

 

Also you can check more Python articles in the below links

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Codeloop
Share via
Copy link
Powered by Social Snap
×