Jan-24-2018, 05:05 PM
from tkinter import * from math import * root = Tk() # Make window root.geometry() #mg/ml text entry MG/ML mg2 = StringVar() mg = Entry(root,textvariable=mg2,width=10, bg="white") mg.grid(row=3,column=3,sticky=W) #text entry WEIGHT WEIGHT2 = StringVar() WEIGHT = Entry(root, textvariable=WEIGHT2,width=10, bg="white") WEIGHT.grid(row=1,column=3,sticky=W) #text entry DOSE dose2 = StringVar() DOSE2 = Entry(root,textvariable=dose2,width=10, bg="white") DOSE2.grid(columnspan=3,row=2,column=4,sticky=W) #dose label>> dose = Label(root, text='Dose ') dose.grid(columnspan=2,row=2,column=0,sticky=W) #weight label>> Dog_weight = Label(root, text='What is the animals weight?') Dog_weight.grid(columnspan=2,row=1,column=0,sticky=W) #drug mg/ml label>> drug_label = Label(root, text='How many mg are in a ml of this drug?') drug_label.grid(columnspan=3,row=3,column=0,sticky=W) #MATH def ding(): global t global cat2 time = 24 Weight3 = WEIGHT2.get() Weight3 = float(Weight3) dose3 = dose2.get() dose3 = float(dose3) mg3 = mg2.get() mg3 = float(mg3) math = Weight3 * dose3 / time / mg3 t = float(math) cat2 = Label(root, text=t, bg="white") cat2.grid(row=9,column=3,sticky=W) button = Button(root, text="ml or mg", command=ding) button.grid(row=7,column=3) #clear button def clear(): global t global cat2 try: t.destroy() except: pass try: cat2.destroy() except: pass button_clear = Button(root, text='clear',command=clear) button_clear.grid(row=10,column=1)In this code the clear button works fine until you change a variable and recalculate before clearing. Then the clear button breaks. So I`m wondering what the issue is?