I am trying to make a program that records user input (drinks) and displays these inputs when a person wants to view them. .
Specifically, I want the drinks to be displayed when the user clicks the 'View Log' button (second_button
). I think this needs to be done in the viewlog
function, but I am stuck with the best way to do this. I am unsure of how to best store the inputs and how to retrieve them.
from tkinter import *
root = Tk()
root.title('Simple App')
first_label = Label(root, text="Welcome to the program", font=('Arial', 20)).pack()
def save_drink(added_drink, top):
global drinks_list
drinks_list = []
newtop = Toplevel(root)
newtop.geometry("200x200")
newtop.title("Drink Added")
label = Label(
newtop,
text= "{} Added".format((added_drink.get())), font=('Mistral 20')).pack()
close_btn = Button(newtop, text='Close', font=('Mistral 20'), command=lambda t=top, n=newtop: close(t,n))
close_btn.pack()
drinks_list.append(added_drink.get())
def add_drink():
top = Toplevel(root)
top.geometry("750x250")
top.title("Record Drink")
label = Label(top, text= "What drink did you have?", font=('Mistral 18')).pack()
added_drink = Entry(top, font=6)
added_drink_string = str(added_drink)
added_drink.pack()
added_drink_button = Button(top, text='Add Drink', font=3,
command=lambda: save_drink(added_drink, top)).pack()
def close(top, newtop):
top.destroy()
newtop.destroy()
def viewlog():
logtop = Toplevel(root)
logtop.title('Drinks Log')
label_text = Label(logtop, text="Today's Drinks", font=('Arial', 20)).pack()
label2 = Label(logtop, text=print(drinks_list), font=('Arial', 16))
# here we need to take the items in drinks_list and display them on a screen
close_btn = Button(logtop, text="Close", pady=20, font=('Times New Roman', 20), command=logtop.destroy).pack()
first_button = Button(root, text="Add drink", command=add_drink).pack()
second_button = Button(root, text="View log", command=viewlog).pack()
root.mainloop()