I am very new to python and I've been trying to do this code where i use a tkinter button command to run a function, it works but the append() is not executing, meaning it does not append to the list.
The list and the function containing the append is outside the class and is then classed within a class through the use of tkinter button command
I've tried putting the function inside the class, it works but the append is not adding into the list again.
import tkinter as tk
from threading import Thread
from queue import Queue
import time
from tkinter import messagebox
LARGE_FONT = ("Verdana", 12)
Receipt = []
prices = []
job_queue = Queue()
Orders = []
class SushiMenuApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (OrderPage, ReceiptPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(OrderPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
def sushichef(job_queue):
while True:
a = job_queue.get()
if a is None:
print("There are no more orders")
break
messagebox.showinfo("Message", "Sushi Chef started doing you order")
time.sleep(a)
print("Your order will be coming to you now")
job_queue.task_done()
class OrderPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Sushi Selections", font=LARGE_FONT)
label.grid(row=0, column=0, columnspan=4)
checkout = tk.Button(self, text="Check Out", command=lambda:controller.show_frame(ReceiptPage))
checkout.grid(row=0, column=4)
for _ in range(4): # 4 Sushi Chefs
thread = Thread(target=sushichef, args=(job_queue,))
thread.start()
Orders.append(thread)
shrimptempura = tk.Button(self, text="Shrimp Tempura",
command= staction)
shrimptempura.grid(row=1, column=0)
def staction():
for item in [60]:
job_queue.put(item)
prices.append(69)
Receipt.append("Shrimp Tempura")
class ReceiptPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Receipt", font=LARGE_FONT)
label.grid(row=0, columnspan=4, sticky="nsew")
fullreceipt= tk.Label(self, text='\n'.join(map(str, Receipt)))
fullreceipt.grid(row=1, columnspan=4, rowspan=48)
sumprice= tk.Label(self, text=sum(prices))
sumprice.grid(row=49, column=1, columnspan=2)
app = SushiMenuApp()
app.mainloop()
I was expecting the output to add the value within the prices.append() and the string within the receipt.append() together along with the job_queue,
expected would be that in the receipt page it would look something like this
Receipt
Shrimp Tempura
70
but the output is that only the job_queue is what i can see as working because the message box was working which was the effect of the job_queue but in the ReceiptPage it would only show
Receipt