Making a unit converter
- 라임 샹큼
- Mar 29
- 2 min read

import tkinter
screen = tkinter.Tk()
screen.title('Mile to km converter')
screen.minsize(width = 300, height = 150)
blank = tkinter.Label()
blank.grid(column=0,row=0)
#is equal to
main_text = tkinter.Label(text = 'is equal to')
main_text.grid(column=0,row =3)
main_text.config(padx = 30)
#miles input
input = tkinter.Entry(width = 5)
input.grid(column=1, row = 1)
input_txt = tkinter.Label(text= 'Miles')
input_txt.grid(column = 2, row = 1)
#kilometer output
output = tkinter.Label(text = '')
output.grid(column=1,row=4)
output_txt = tkinter.Label(text= 'Km')
output_txt.grid(column = 2, row = 4)
#converter button
def button_action():
km = float(input.get()) * 1.609
output.config(text =km)
button = tkinter.Button(text = 'Calculate',command = button_action)
button.grid(column = 1,row=6)
screen.mainloop()
What I learned
Can add image to screen:screen.addshape(image) turtle.shape(image)
#first line tells screen image exists, second tells turtle to wear it
list comprehension
new_list = [new_item for item in list]
conditional list comprehension:
new_list = [new_item for item in list if list]
dictionary comprehension:
new_dict = {new_key: new_value for item in list}
new_dict = {new_key:new_value for (key,value) in dict.items()}
Can loop through rows of a data frame:
for (index, row) in data_dict.iterrows():
print(row.key)
label centering and making it actually appear on screen in tkinter
my_label.pack(side = 'bottom','right''left')/ my_label.pack(expanse = True)*args: can accept any number of arguments
sum_ = 0def add(*args): global sum_ for num in args: sum_ += num print(sum_)add(1,2,3,4)**kwargs: keyword arguments, in the form of dictionaries
.get() function:
when retrieving values from a dictionary with keys, use square brackets to indicate key. But in this case, if there is no value for the key, it will create an error. To prevent this, use the .get() function
ex) from **kw
kw.get('girl')
even if there is no key for 'girl' it will just return None
#label configuration
my_label['text'] = 'New text' #changing im a label to new text
my_label.config(text = 'New text') #same as above
When inserting a function as arguments, can remove parenthesises :
button = tkinter.Button(text = 'click me', command=button_clicked)Entry(basically input):
input = tkinter.Entry(width = 10)input.pack()input.get() -> this is the value of the user's inputtkinter pack(): with every pack() called, will enter the widget right under the previous widget
tkinter position function 2.: place()
Can place exact coordinates. Move with + values only, the top left corner being (0,0)
tkinter position function 3.: grid()
Can create grids by rows and columns and place it in order
The positon functions cannot be used together- just use one till the end
grid(): Don't really think about how it is divided. Have to count from 0, the first column and row are 0
Creating padding/borders: with the screen(), do screen.config(padx =, pady = )
screen.config(padx = 20, pady= 20)
Calculate Your Age Instantly with Our Smart Age Calculator! 🧮
Ever wondered exactly how old you are — not just in years, but in months, days, hours, or even seconds? Our Age Calculator is the easiest and most accurate way to find out!
Whether you're planning a birthday party, tracking milestones, or just having fun with friends, our tool delivers precise results in real time. It's more than just a number — it's your life's timeline!
🔍 Why Use Our Online Age Calculator?
✅ Instant & Accurate: Just input your date of birth, and get a detailed breakdown of your age in years, months, days, hours, minutes, and seconds — updated live.✅ No Hassle, No Sign-Up: Use it right away without creating…