Skip to content

Python training - 100 days of code: The complete Python Pro Bootcamp for 2023

Notifications You must be signed in to change notification settings

shelbyblanton/miles-to-km-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Miles to Kilometers Converter

By Dr. Angela Yu

Day 27 of 100: Tkinter, *args, **kwargs, and Creating GUI Programs

Project Specs

Using TkInter, develop an application that converts miles to kilometers.

This application is written with Python 3.11.

alt text

Main Features

The application displays two interactive pieces:

  • A form input box where a user will enter the number of miles they want converted to kilometers
  • A Calculate button that triggers the conversion and outputs the kilometers.

Usage & Requirements

This project uses one library:

  • TkInter

Workflow

Tkinter is used to create a Graphic User Interface (GUI) with a width of 250 pixels and a height of 120 pixels:

window = Tk()
window.title("Mile to Km Converter")
window.minsize(width=250, height=120)
window.config(padx=20, pady=20)

Then we add the miles form input to the interface:

# Miles input
miles = Entry(width=8, justify="center")
miles.grid(column=1, row=0)

We use Tkinter's label functionality to add all of our text to the interface:

# create label
label = Label(text="Miles", font=("Arial", 14))
label.grid(column=2, row=0)

# Is equal to label
iet_label = Label(text="is equal to", font=("Arial", 14))
iet_label.grid(column=0, row=1)

# Result label
res_label = Label(text="0", font=("Arial", 14))
res_label.grid(column=1, row=1)

# KM label
km_label = Label(text="Km", font=("Arial", 14))
km_label.grid(column=2, row=1)

And then we add the calculate button that will trigger the conversion:

# Calculate button
button = Button(text="Calculate", command=calculate)
button.grid(column=1, row=2)

Getting Started

All of the commands below should be typed into the Python terminal of your IDE (I use PyCharm for my Python Development).

First, clone the repository from Github and switch to the new directory:

$ git clone git@github.com:shelbyblanton/miles-to-km-converter.git

Then open the project in PyCharm.

Setup is complete!

Click Run in PyCharm to see the app in action.

Author & Credits

Programmed by M. Shelby Blanton under the instructional guidance of Dr. Angela Yu via Udemy.com.

About

Python training - 100 days of code: The complete Python Pro Bootcamp for 2023

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages