Blog

6/recent/ticker-posts

Creating Python GUI Application with Tkinter


 

Creating Python GUI Application with Tkinter



The GUI (Graphical User Interface), is a system of interactive user interface that allows users to communicate with electronic graphical components like icons, buttons and menu.


 

Python Tkinter Number Guessing Game


                                       

In this article, we  will learn how to create a python tkinter number guessing game. 

What Is Tkinter?

Tkinter is a Python GUI library that when combined with python provides fast and easy way to create GUI Applications. Tkinter is popular, simple and widely used and also has a ton of references to get you started.

Creating A Window

Let's start by creating a window. It's really quite simple using Tkinter. Let's create a new python file called main.py.

python
from tkinter import *
root = Tk()
root.geometry('900x600')
root.mainloop()

output: ......


A blank empty window.


In the first line inside the code snippets, we imported all the functions for the Tkinter module. Using import *, will import all. In the second line we used " root " and assigned it to Tk() which is the standard name for initializing the Tk root widget. The root widget, which is the main window and our parent window, has to be created before any other windows. Also, there can be only one root. Then we gave our window a size using geometry with width: 900 and height: 600. Finally, the last line runs the main loop event . 

Now, after running our window you will noticed that the window is not aligned exactly at the center of the screen. So let's fix it.


python
from tkinter import *

root = Tk()

# Making window align to the center
height = 600
width = 900
x = (root.winfo_screenwidth()//2)-(width//2)
y = (root.winfo_screenheight()//2)-(height//2)
root.geometry('{}x{}+{}+{}'.format(width, height, x, y))

root.mainloop()


Watch The Tutorial Video Below For a More Detailed step by step on how to create a Python Tkinter GUI Application


Full Tutorial Video From YouTube ..

Summary

In this article, we looked at the graphical user interface of a modern python Tkinter number guessing game.

My name is Sen Gideons, If you have any questions or comments about this tutorial, please feel free to leave them in the comments section below.



Post a Comment

0 Comments

Ad Code

Responsive Advertisement

Hot Post