How would I create a reset button for my program relating with the following code?

Viewed 13406

I am trying to add a reset button but I can't seem to get it to work. I created a main in order to refer back to it when the button is pressed but no luck. Any ideas?

import sys
from tkinter import *
import math

def main():
    def closeWin():
        myGui.destroy()                  #Close Window Function


    def kiloFunc():
        myText = kiloMent.get()          #Kilometers to Miles Fuction
        convert = 0.62
        miles = myText * convert
        finalKilo = Label(text = miles,fg='red',justify='center').place(x=200,y=80)


    def mileFunc():
        myText2 = mileMent.get()         #Miles to Kilometers Function
        convertTwo = myText2 // 0.62    
        finalMile = Label(text = convertTwo, fg = 'red',justify='center').place(x=200,y=170)

    myGui = Tk()

    kiloMent = IntVar()
    mileMent = IntVar()

    myGui.title("Distance Converter")
    myGui.geometry("450x200+500+200")

    myLabel = Label(text="Welcome! Please enter your value then choose your option:",fg="blue",justify='center')
    myLabel.pack()

    kiloEntry = Entry(myGui, textvariable = kiloMent,justify='center').pack()

    kilo2milesButton = Button(text = "Kilometers to Miles!", command = kiloFunc).pack()

    mileEntry = Entry(myGui, textvariable = mileMent,justify='center').place(x=130,y=105)

    miles2kiloButton = Button(text = "Miles to Kilometers!", command = mileFunc).place(x=150,y=135)

    reset = Button(text = "Reset Values!", command = main).place(x=10,y=165)

    quit = Button(text="Quit", command = closeWin).place(x=385,y=165)


    myGui.mainloop()

main()
2 Answers
Related