Hello I have recently been learning python and I was practicing ... I just can't understand the reason for the error as it seems to me that I define inside the buttons. If someone kindly can help me I would be very grateful
I don't know how to go on anymore and I don't understand where the mistake is, I would like to be able to understand it but I can't do it, can you explain it to me?
windows = tk.Tk()
windows.geometry("400x350")
windows.title("Gym Tracker")
windows.resizable(False, False)
frame1 = Frame(windows, width=150, height=30, highlightcolor="white",highlightbackground="black", highlightthickness=1).place(x=120, y=2)
label1 = Label(windows, text="GYM TRACKER").place(x=150, y=7)
frame2 = Frame(windows, width=500, height=1, highlightcolor="white",highlightbackground="black", highlightthickness=1).place(x=2, y=45)
labelmes = Label(windows, text="Mese").place(x=110, y=60)
combobox = Combobox(windows, values=['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno','Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre']).place(x=200, y=60)
entry2 = tk.Entry(windows)
labealt = Label(windows, text="Altezza").place(x=110, y=90)
textbox = Text(windows, width=17, height=1).place(x=200, y=90)
entry3 = tk.Entry(windows)
labelpeso = Label(windows, text="Peso").place(x=110, y=120)
textbox = Text(windows, width=17, height=1).place(x=200, y=120)
entry4 = tk.Entry(windows)
labelmmagra = Label(windows, text="Massa Magra").place(x=110, y=150)
textbox = Text(windows, width=17, height=1).place(x=200, y=150)
entry5 = tk.Entry(windows)
labelmgrassa = Label(windows, text="Massa Grassa").place(x=110, y=180)
textbox = Text(windows, width=17, height=1).place(x=200, y=180)
entry6 = tk.Entry(windows)
# Combobox Utente
labelutente = Label(windows, text="Utente").place(x=110, y=210)
combobox = Combobox(windows, values=['Erika', 'Lorenzo']).place(x=200, y=210)
entry7 = tk.Entry(windows)
b1 = tk.Button(windows, text="Importa", command=delete ,width=8,`enter code here`height=1).place(x=170,y=310)
b2 = tk.Button(windows, text="Avanti", width=8,height=1,command=nextpage).place(x=300,y=310)
b3 = tk.Button(windows, text='Salva', width=8, height=1, command=save).place(x=50, y=310)
def delete():
entry2.delete(0, tk.END)
entry3.delete(0, tk.END)
entry4.delete(0, tk.END)
entry5.delete(0, tk.END)
entry6.delete(0, tk.END)
entry7.delete(0, tk.END)
def nextpage():
labelmes.destroy()
labealt.destroy()
labelpeso.destroy()
labelmmagra.destroy()
labelmgrassa.destroy()
labelutente.destroy()
b1.destroy()
b2.destroy()
b3.destroy()
def save():
mese = entry2.get()
altezza = entry3.get()
peso = entry4.get()
mmagra = entry5.get()
mgrassa = entry6.get()
utente = entry7.get()
wb = Workbook()
ws = wb.active
ws['A1'] = "Mese"
ws['B1'] = "Altezza"
ws['C1'] = "Peso"
ws['D1'] = "Massa Magra"
ws['E1'] = "Massa Grassa"
ws['F1'] = "Utente"
ws['A2'] = mese
ws['B2'] = altezza
ws['C2'] = peso
ws['D2'] = mmagra
ws['E2'] = mgrassa
ws['F2'] = utente
wb.save(r'C:\Users\lricci\Desktop\SERVER\web\Gym Tracker\Gym Tracker v1.0\track.xlsx')
showinfo("Hai salvato correttamente")
file = pd.read_excel("track.xlsx")
all = [file]
append = pd.concat(all)
append.to_excel("track.xlsx",index=False)
windows.mainloop()
CodePudding user response:
change name your function to another name delete
CodePudding user response:
This line
b1 = tk.Button(windows, text="Importa", command=delete ,width=8,`enter code here`height=1).place(x=170,y=310)
Attaches the button to the delete
function, however, at the time you're executing it you haven't defined the delete function (you do that slightly later).
Try moving that line below your def delete():