Standard GUI Unit Converter using Tkinter in Python
In this article, we will learn how to create a standard converter using tkinter. Now we are going to create an introduction window that displays loading bar, welcome text, and user’s social media profile links so that when he/she shares his code with some others, they can contact the author using those resources. It looks like a bit lengthy code, but believe me, guys if you start understanding it is so easy and i divided the code into blocks which helps you to understand better.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Steps to create an introduction window:
- First of all, “Tkinter” and “webbrowser” modules to be imported.
- Create an intro class that fires the introduction window.
- Create a Toplevel Tkinter window in order to use full features of a window.
- Place a welcome label on the top of the window.
- Create one “ttk.Progressbar” which gives us loading effect.
- Finally, create four buttons and provide your social media links using “webbrowser” module.
- And you have to download/create four images to represent your social media links.
Below is the Intro class implementation :
Steps to create a Converter window:
- Create a separate class for the converter window.
- We will split the window into two halves horizontally with suitable color combination.
- And now we need to create two Tkinter entry boxes, two Tkinter labels, two buttons to activate a list box, one hamburger icon for the menu.
- Place the above things at their respective positions using .place method of a Tkinter widget.
- Now we need to feed the formulae of each unit, to convert into other units, in separate dictionaries.
- Feed the input values in the main function and pass them while initializing or using the setter method of a class
- We need to create shift function using which the user will be able to shift from one parameter to another parameter.
Below is the Converter class implementation :
Now create a main function and create a set of dictionaries to feed unit formulae values and call the “intro()” class to fire the converter. Here you can see your contact links, loading bar etc. You will also need to create a “center” function if you want your window to be fired at the center of the screen.
Below is the Full code implementation :
- You need to install “tkinter” and “webbrowser” libraries.
- Creating an introduction window is your choice(It’s not mandatory). But I suggest you to create that one also.
- You need to create toplevel windows because we can’t destroy a main window as it may corrupt all our project.
- You don’t need to install various IDE’s, it works perfectly fine on python IDLE.