DEV Community

dhakshinesh
dhakshinesh

Posted on β€’ Edited on

3 2

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
Enter fullscreen mode Exit fullscreen mode

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 module
from tkinter import *
import tkinter

#assigning a "root" as the main window for our application
root = tkinter.Tk()

root.mainloop()
Enter fullscreen mode Exit fullscreen mode

Now if you run the following code, you can see a window as shown below.

Tkinter Application window

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')
Enter fullscreen mode Exit fullscreen mode

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 font
Label(root, text="Hello World!", font=('Jokerman',25,'bold')).pack()

#A text with red background
Label(root, text="Hello World!",bg='red', font=10 ).pack()

#A text with red color
Label(root, text="Hello World!",fg='red', font=10 ).pack()
Enter fullscreen mode Exit fullscreen mode

Here's the complete code of the program that we just made,

#importing the tkinter module
from tkinter import *
import tkinter

root = 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 font
Label(root, text="Hello World!", font=('Jokerman',25,'bold')).pack()
#A text with red background
Label(root, text="Hello World!",bg='red', font=10 ).pack()
#A text with red color
Label(root, text="Hello World!",fg='red', font=10 ).pack()
root.mainloop()
Enter fullscreen mode Exit fullscreen mode

Here's the output of the following code,

Hello World!

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.πŸ˜„

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
geeth profile image
Geethegreat β€’

wow you are lit af

nextjs tutorial video

Youtube Tutorial Series πŸ“Ί

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series πŸ‘€

Watch the Youtube series

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay