top of page

Making a unit converter

Mar 29, 2025
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 input
  • tkinter 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)


 
 
 

Recent Posts

See All
Stock market price alerter

Lately I’ve been getting API data from existing data and using it to get actual live data. This is done by importing requests. This was...

 
 
 
Making a better quiz ui

I reencountered classes again. I remember I had a a hard time learning how classes were different from simply defining functions. It was...

 
 
 

3 Comments


zusazuh-ufa47
Oct 29

One thing I enjoy about following football is seeing an underdog put up a much better performance than expected. A team with fewer resources might have a solid defensive plan and take advantage of a couple of mistakes from the favourite. Of course, one surprising result doesn't necessarily mean the weaker team is suddenly better Bitkingz casino overall. Matchups, injuries, and tactics can all affect how a game unfolds. I think this is also why league positions alone don't tell you everything about an upcoming fixture. Two teams can have very different records, yet the actual match can be much closer than people initially expect.

Like

guyeler_ama88
Oct 22

When I watch football, I sometimes wonder how much attention people pay to the odds once the match actually starts. It seems easy to get distracted by every small change in the numbers instead of watching how the teams are playing. A team can have a lot of possession without creating many real chances, while another side powerup casino might look quiet and then score from one counterattack. Statistics help explain some of these situations, but they don't capture everything happening on the pitch. I find the game itself more interesting when I'm not constantly checking numbers, especially during a close match that could go either way.

Like

COP
COP
May 10, 2025

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…

Like

© 2024 by GifTED. Powered and secured by Wix

bottom of page