Creating Python GUI Application with Tkinter
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
.
from tkinter import *
root = Tk()
root.geometry('900x600')
root.mainloop()
output: ......
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.
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.
- More From This Blog
- How to Make Python Tkinter Page Fullscreen
- Creating Python GUI Application with Tkinter?
- How to Customize Prev/Next Buttons in React SwiperJs
- Creating Multiple Window Frames with Python Tkinter
- Python Tkinter Loading Screen - Splash Screen GUI?
- Python Tkinter Modern Professional Login Page GUI
- Student Registration System with Python Tkinter
- Python Tkinter Modern GUI Login And Sign Up System
- How to create a Splash Screen using Tkinter?
0 Comments