An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
Creating Your First Application On Python Using Tkinter
What is Tkinter
For those who don't know what tkinter is, It is basically a python module for making GUI(Graphical User Interface), in which we can do all the beautiful things on the frontend and hide your messy backend code..
Getting Started
First off to get started, we need to Install Tkinter using pip
On your terminal type,
pip install tk
Note: You will need the latest version of python(3.9.0) or higher.
Now to the fun stuff ..
After installing tkinter, you are ready to make your first python application.
On your text-editor, create a python file(.py) and then you'll be needing the following code to set up tkinter on your application.
#importing the tkinter modulefrom tkinter import *import tkinter#assigning a "root" as the main window for our applicationroot = tkinter.Tk()root.mainloop()
Now if you run the following code, you can see a window as shown below.
This is the place all of our widgets which are the elements are going to be shown.
Before we go ahead, We need to make a fixed size for our application.
Just after assigning the root = tkinter.Tk() add,
root.geometry('500x500')
What is better than making a "Hello World!" program?
Now we're going to a widget by tkinter which lets us make some cool text.
#Just a basic text.Label(root, text="Hello World!").pack()#Just a basic text but bigger.Label(root, text="Hello World!", font=20).pack()#A bold text with a different fontLabel(root, text="Hello World!", font=('Jokerman',25,'bold')).pack()#A text with red backgroundLabel(root, text="Hello World!",bg='red', font=10 ).pack()#A text with red colorLabel(root, text="Hello World!",fg='red', font=10 ).pack()
Here's the complete code of the program that we just made,
#importing the tkinter modulefrom tkinter import *import tkinterroot = tkinter.Tk()root.geometry('500x500')#Main#Just a basic text.Label(root, text="Hello World!").pack()#Just a basic text but bigger.Label(root, text="Hello World!", font=20).pack()#A bold text with a different fontLabel(root, text="Hello World!", font=('Jokerman',25,'bold')).pack()#A text with red backgroundLabel(root, text="Hello World!",bg='red', font=10 ).pack()#A text with red colorLabel(root, text="Hello World!",fg='red', font=10 ).pack()root.mainloop()
Here's the output of the following code,
Congrats you've successfully made your first python application!
That's it for this tutorial on making your first application, If you want to see more widgets by tkinter you can check this link
And by the way this is my first dev-post, I would really like to see what you think about it.
Original Link: https://dev.to/dhakshinesh/creating-your-first-application-on-python-using-tkinter-131g
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To