Today we're going to use a usefull library in python to build awesome applications. We'll use : Tkinter
.
In this first part, we'll know how to create the base of our application. In a second part, we'll see the different widgets, this module propose to us and how to display them. And finally, in a third part, the inputs and actions.
The module :
First Tkinter is a module that can create some GUI applications for all plateforms as Windows, Mac OS and Linux. If you have Python already installed on your computer, you have surely tkinter with it. If it's not you can run this command in the console :
pip install tkinter
The base of the app :
So, let's start with the script. Create a file with the .py
extension (PS : you can use .pyw
extension if you want to hide the console when the script is running).
In this empty file, insert the import of Tkinter :
import tkinter # Basic import
from tkinter import * # Import all propreties from tkinter module
We'll use the second import because it's a better way to do.
Now, we can create a variable that store the application :
app = Tk()
After that, we can asign some options to the app :
1) A title : app.title("Our Application")
2) A size by default : app.geometry("600x400")
-> "widthxheight"
And now, we can finally finish the programm by this line :
app.mainloop()
Like that our app can run on the screen.
Full script :
from tkinter import *
app = Tk()
app.title("Our Application")
app.geometry("600x400")
app.mainloop()
Output :
Yeah, an exmpty screen... But it's a good start.
As you see, create a desktop application with tkinter is very simple. In the next post, we'll see the different widgets we can add to our app and how to display them on the screen.
If you have some questions on this first part, please write it in the comment section below.
I hope this help you. And see you soon. Bye bye ππ¨βπ»
Top comments (0)