I am working on an assignment which involves working with openpyxl, tkinter and pandas. I need to do some calculations in excel based on one input (avg_trips)
This is the current code. After uploading the file the code just asks for input in the terminal. but I want it to ask for input in the tkinter window
def open_file():
file = askopenfile(mode ='a+', filetypes =[('Excel Files', '*.xlsx *.xlsm *.sxc *.ods *.csv *.tsv')])
wb = openpyxl.load_workbook(filename = file.name)
wb.create_sheet("Results")
avg_trips = float(input("Enter Shipping Frequency: "))
This is the tkinter code that I tried:
root = tk.Tk()
root.title("Optimization")
root.geometry('500x450')
frq = Label(root,text="Enter Shipping Frequency: ")
frq.pack()
frq.place(x =105,y=180)
def printtext():
global e
avg_trips = int(e.get())
e = Entry(root)
e.pack()
e.place(x=260,y=180)
button = Button(root,text='okay',command=printtext)
button.pack(side='bottom')
button.place(x=230,y=220)
lbl=Label(root, text="Optimization", fg='blue', width = 450,bg = 'light blue', font=("Helvetica", 16))
lbl.pack(side=TOP, fill=X)
btn = Button(root, text ='Upload File', command = open_file)
btn.place(x=210, y=150)
foot=Label(root, text="2021 Optimization",fg='blue',width = 450,bg = 'light blue',font=("Helvetica", 8))
foot.pack(side=BOTTOM, fill=X)
# avg_trips = Entry(root)
# # avg_trips = x.get()
btn = Button(root, text ='Run', command = excel)
btn.place(x=230, y=250)
root.mainloop()
I gave the same variable name (avg_trips) but I am getting this error:
NameError: name 'avg_trips' is not defined
How do I make it where the input is asked in the tkinter file and the button triggers the rest of the process?