1
\$\begingroup\$

This application is for restaurant patrons to know how long they have to wait in line. We would like to design a more sophisticated GUI interface, but do not know how to go about it. Please let me know if there are any appropriate libraries or other resources.

import tkinter as tk
from tkinter import messagebox as message
import tkinter.ttk as ttk


wait_que=[]
list_four_table=[]
list_two_table=[]
list_one_table=[]
list_four_table_situ = []
list_two_table_situ = []
list_one_table_situ = []
four_table=[]
two_table=[]
one_table=[]


enpty = 0 # Vacant Seat
pre_oreder = 1 # Occupied, but not yet order
post_order = 2 # Ordered but dish has not yet come
post_dish = 3  # Already dish arrived 

class MainFrame(tk.Frame):
    def __init__(self, master = None):
        super().__init__(master)
        br = tk.Button(self, text = "Show Waiting Time", command = self.show_screen_br, width=28)
        bo = tk.Button(self, text = "Check Seat Situation", command = self.show_screen_bo, width=28)
        bs = tk.Button(self, text = "Register Number of Seats", command = self.show_screen_bs, width=28)
        bc = tk.Button(self, text = "Change Seat Situation", command = self.show_screen_bc,width=28)
        ba = tk.Button(self, text = "Add Waiting Queue", command = self.show_screen_ba, width=28)

        bs.pack(padx =10, pady = 10)
        bo.pack(padx =10, pady = 10)
        bc.pack(padx =10, pady = 10)
        ba.pack(padx =10, pady = 10)
        br.pack(padx =10, pady = 10)

    # "Show Waiting Time" Screen
    def show_screen_br(self):
        global screen_br
        global entry_br
        screen_br = tk.Toplevel()
        screen_br.title("Show Waiting Time")
        screen_br.geometry('300x150')

    # if there is no queue
        if wait_que == []:
            label_wait_num = tk.Label(screen_br, text = 'How many are you')
            b_close = tk.Button(screen_br, text = "Close", command = self.quit_window_br)
            entry_br = tk.Entry(screen_br, font=("Helvetica", 24))
            b_result = tk.Button(screen_br, text = "Show Waiting Time", command = self.show_wait_time)

            label_wait_num.pack()
            b_close.pack(side = "bottom")
            entry_br.pack()
            b_result.pack()
    # if there is any queue
        else:
            label_wait_num = tk.Label(screen_br, text = 'What number are you in line for?')
            b_close = tk.Button(screen_br, text = "Close", command = self.quit_window_br)
            entry_br = tk.Entry(screen_br, font=("Helvetica", 24))
            b_result = tk.Button(screen_br, text = "Show Waiting Time", command = self.show_wait_time)

            label_wait_num.pack()
            b_close.pack(side = "bottom")
            entry_br.pack()
            b_result.pack()

    # "Check Seat Situation" Screen
    def show_screen_bo(self):
        global screen_bo
        global four_table
        global two_table
        global one_table
        screen_bo = tk.Toplevel()
        screen_bo.title("Check Seat Situation")
        screen_bo.geometry('735x500')

        bo_close = tk.Button(screen_bo, text = "Close", command = self.quit_window_bo)

        # Seats for 4 persons
        if four_table==[]:
            message.showinfo("Caution","Seats for 4 perons are not registerd. Please register from 'Register Number of Seats' on Home Screen")
        else:
            tbl_four = ttk.Treeview(screen_bo)
            tbl_four['columns'] = ('number', 'four_situation')
            tbl_four['show'] = 'headings'
            tbl_four.heading('number', text = 'Seat Number')
            tbl_four.heading('four_situation', text = 'Situation')

            tbl_four.column('number'  , width=100)
            tbl_four.column('four_situation' , width=100)

            for i in range(four_table):
                table_num = str(list_four_table[i])
                tbl_four.insert('', 'end', values=(table_num,jp_dic_four_table[table_num]))

            tbl_four.pack(side = tk.LEFT, padx = 20)

        # Seats for 2 persons
        if two_table==[]:
            message.showinfo("Caution","Seats for 2 perons are not registerd. Please register from 'Register Number of Seats' on Home Screen")
        else:
            tbl_two = ttk.Treeview(screen_bo)
            tbl_two['columns'] = ('number', 'two_situation')
            tbl_two['show'] = 'headings'
            tbl_two.heading('number', text = 'Seat Number')
            tbl_two.heading('two_situation', text = 'Situation')

            tbl_two.column('number'  , width=100)
            tbl_two.column('two_situation' , width=100)

            for i in range(two_table):
                table_num = str(list_two_table[i])
                tbl_two.insert('', 'end', values=(table_num,jp_dic_two_table[table_num]))

            tbl_two.pack(side = tk.LEFT, padx = 20)

        # Seats for 1 person
        if one_table==[]:
            message.showinfo("Caution","Seats for 1 peron are not registerd. Please register from 'Register Number of Seats' on Home Screen")
        else:
            tbl_one = ttk.Treeview(screen_bo)
            tbl_one['columns'] = ('number', 'one_situation')
            tbl_one['show'] = 'headings'
            tbl_one.heading('number', text = 'Seat Number')
            tbl_one.heading('one_situation', text = 'Situation')

            tbl_one.column('number'  , width=100)
            tbl_one.column('one_situation' , width=100)

            for i in range(one_table):
                table_num = str(list_one_table[i])
                tbl_one.insert('', 'end', values=(table_num,jp_dic_one_table[table_num]))

            tbl_one.pack(side = tk.LEFT, padx = 20)

        bo_close.pack(side = tk.BOTTOM)
    
    
    # "Register Number of Seats" Screen
    def show_screen_bs(self):
        global screen_bs
        global entry_four_table
        global entry_two_table
        global entry_one_table
        screen_bs = tk.Toplevel()
        screen_bs.title("Register Number of Seats")
        screen_bs.geometry('735x300')

        b_close = tk.Button(screen_bs, text = "Close", command = self.quit_window_bs)
        label_four_table = tk.Label(screen_bs, text = 'Tell me how many seats you have for 4 persons')
        label_two_table = tk.Label(screen_bs, text = 'Tell me how many seats you have for 2 persons')
        label_one_table = tk.Label(screen_bs, text = 'Tell me how many seats you have for 1 persons')
        entry_four_table = tk.Entry(screen_bs, font=("Helvetica", 24))
        entry_two_table = tk.Entry(screen_bs, font=("Helvetica", 24))
        entry_one_table = tk.Entry(screen_bs, font=("Helvetica", 24))
        b_seat = tk.Button(screen_bs, text = "Register Seats", command = self.situ)

        b_close.pack(side = "bottom")
        label_four_table.pack()
        entry_four_table.pack()
        label_two_table.pack()
        entry_two_table.pack()
        label_one_table.pack()
        entry_one_table.pack()
        b_seat.pack()


    # "Change Seat Situation" Screen
    def show_screen_bc(self):
        global screen_bc
        global entry_table_type
        global entry_table_num
        global entry_table_situ
        global four_table
        global two_table
        global one_table
        screen_bc = tk.Toplevel()
        screen_bc.title("Change Seat Situation")
        screen_bc.geometry('600x700')
    
        b_close = tk.Button(screen_bc, text = "Close", command = self.quit_window_bc,)
        label_table_type = tk.Label(screen_bc, text = 'Which type of seats you will change. Type in 4 or 2 or 1')
        label_table_num = tk.Label(screen_bc, text = 'What is the number of the seat. Type in number only')
        label_table_situ = tk.Label(screen_bc, text = 'What is the situation of the seat.(Vacant:0、Waiting Order:1、Waiting Dish:2、Dish Arrived:3)')
        entry_table_type = tk.Entry(screen_bc, font=("Helvetica", 24), width = 5)
        entry_table_num = tk.Entry(screen_bc, font=("Helvetica", 24), width = 5)
        combobox_table_situ = ttk.Combobox(screen_bc, values=(0, 1, 2, 3), font=("Helvetica", 24) , state="readonly")
        b_situ = tk.Button(screen_bc, text = "Change Seat Situation", command = self.change_situ)
        label_exp_1 = tk.Label(screen_bc, text = "Seat for ")
        label_exp_2 = tk.Label(screen_bc, text = 'No.')
        label_exp_3 = tk.Label(screen_bc, text = 'Change to')

        b_close.pack(side = "bottom")
        label_table_type.pack()
        label_exp_1.pack()
        entry_table_type.pack()
        label_table_num.pack()
        label_exp_2.pack()
        entry_table_num.pack()
        label_table_situ.pack()
        label_exp_3.pack()
        combobox_table_situ.pack()
        b_situ.pack(pady=20)
    
        #Seats for 4 perosons
        if four_table==[]:
            message.showinfo("Caution","Seats for 4 perons are not registerd")
        else:
            tbl_four = ttk.Treeview(screen_bc)
            tbl_four['columns'] = ('number', 'four_situation')
            tbl_four['show'] = 'headings'
            tbl_four.heading('number', text = 'Seat Number')
            tbl_four.heading('four_situation', text = 'Situation')

            tbl_four.column('number'  , width=100)
            tbl_four.column('four_situation' , width=100)

        
            for i in range(four_table):
                table_num = str(list_four_table[i])
                tbl_four.insert('', 'end', values=(table_num,jp_dic_four_table[table_num]))
            
            tbl_four.pack(side = tk.LEFT, padx = 20, pady=20)

        #Seats for 2 perosons
        if two_table==[]:
            message.showinfo("Caution","Seats for 2 perons are not registerd")
        else:
            tbl_two = ttk.Treeview(screen_bc)
            tbl_two['columns'] = ('number', 'two_situation')
            tbl_two['show'] = 'headings'
            tbl_two.heading('number', text = 'Seat Number')
            tbl_two.heading('two_situation', text = 'Situation')

            tbl_two.column('number'  , width=100)
            tbl_two.column('two_situation' , width=100)

            for i in range(two_table):
                table_num = str(list_two_table[i])
                tbl_two.insert('', 'end', values=(table_num,jp_dic_two_table[table_num]))

            tbl_two.pack(side = tk.LEFT, padx = 20, pady=20)

        #Seats for 1 peroson
        if one_table==[]:
            message.showinfo("Caution","Seats for 1 peron are not registerd")
        else:
            tbl_one = ttk.Treeview(screen_bc)
            tbl_one['columns'] = ('number', 'one_situation')
            tbl_one['show'] = 'headings'
            tbl_one.heading('number', text = 'Seat Number')
            tbl_one.heading('one_situation', text = 'Situation')

            tbl_one.column('number'  , width=100)
            tbl_one.column('one_situation' , width=100)

            for i in range(one_table):
                table_num = str(list_one_table[i])
                tbl_one.insert('', 'end', values=(table_num,jp_dic_one_table[table_num])) 
        
            tbl_one.pack(side = tk.LEFT, padx = 20, pady=20)

    # "Add Waiting Queue" Screen
    def show_screen_ba(self):
        global screen_ba
        global entry_add_que
        screen_ba = tk.Toplevel()
        screen_ba.title("Add Waiting Queue")
        screen_ba.geometry('300x150')

        b_close = tk.Button(screen_ba, text = "Close", command = self.quit_window_ba)
        label_add_que = tk.Label(screen_ba, text = 'How many of the customer just queued')
        entry_add_que = tk.Entry(screen_ba, font=("Helvetica", 24))
        b_que = tk.Button(screen_ba, text = "Add Waiting Que", command = self.add_que)
        label_que = tk.Label(screen_ba, text = "Current queue is"+str(wait_que)+".")

        b_close.pack(side = "bottom")
        label_add_que.pack()
        entry_add_que.pack()
        b_que.pack()
        label_que.pack(pady=10)

    def quit_window_br(self):
        global screen_br
        screen_br.destroy()

    def quit_window_bo(self):
        global screen_bo
        screen_bo.destroy()

    def quit_window_bs(self):
        global screen_bs
        screen_bs.destroy()

    def quit_window_bc(self):
        global screen_bc
        screen_bc.destroy()

    def quit_window_ba(self):
        global screen_ba
        screen_ba.destroy()
    

    def situ(self):
        self.all_situ_table()

    def change_situ(self):
        self.change_table_situ()

    def add_que(self):
        self.add_wait_que()


    # Name each seats
    def name_four_table(self): 
        global list_four_table
        global four_table
        try:
            four_table = int(entry_four_table.get())
            for i in range(four_table):
                factor_four_table = ''
                four_table_mod = factor_four_table.replace('','4P Seats No'+str(i+1))
                list_four_table.append(four_table_mod)
        except ValueError:
            message.showerror("Error","Can't change to integer. Try again")
        except:
            message.showerror("Error","Unexpected Error. Try again")

    def name_two_table(self): 
        global list_two_table
        global two_table
        try:
            two_table = int(entry_two_table.get())
            for i in range(two_table):
                factor_two_table = ''
                two_table_mod = factor_two_table.replace('','2P Seats No'+str(i+1))
                list_two_table.append(two_table_mod)
        except ValueError:
            message.showerror("Error","Can't change to integer. Try again")
        except:
            message.showerror("Error","Unexpected Error. Try again")


    def name_one_table(self): 
        global list_one_table
        global one_table
        try:
            one_table = int(entry_one_table.get())
            for i in range(one_table):
                factor_one_table = ''
                one_table_mod = factor_one_table.replace('','1P Seats No'+str(i+1))
                list_one_table.append(one_table_mod)
        except ValueError:
            message.showerror("Error","Can't change to integer. Try again")
        except:
            message.showerror("Error","Unexpected Error. Try again")
        

    # Make dictionary to match seat name and seat situation
    def situ_four_table(self):
        global list_four_table_situ
        global list_four_table
        global dic_four_table
        global jp_dic_four_table
        global time_dic_four_table
        self.name_four_table()
        for i in range(four_table):
            factor_four_table = ''
            four_table_mod = factor_four_table.replace('',str(0))
            list_four_table_situ.append(four_table_mod)
        dic_four_table = dict(zip(list_four_table, list_four_table_situ))
        # Dictionary to show seat status in words
        jp_dic_four_table = dic_four_table.copy() 
        time_dic_four_table = dic_four_table.copy()
        for i in jp_dic_four_table:
            jp_dic_four_table[i] = 'Vacant'

    def situ_two_table(self):
        global list_two_table_situ
        global list_two_table
        global dic_two_table
        global jp_dic_two_table
        global time_dic_two_table
        self.name_two_table()
        for i in range(two_table):
            factor_two_table = ''
            two_table_mod = factor_two_table.replace('',str(0))
            list_two_table_situ.append(two_table_mod)
        dic_two_table = dict(zip(list_two_table, list_two_table_situ))
        jp_dic_two_table = dic_two_table.copy()
        time_dic_two_table = dic_two_table.copy()
        for i in jp_dic_two_table:
            jp_dic_two_table[i] = 'Vacant' 

    def situ_one_table(self): 
        global list_one_table_situ
        global list_one_table
        global dic_one_table
        global jp_dic_one_table
        global time_dic_one_table
        self.name_one_table()
        for i in range(one_table):
            factor_one_table = ''
            one_table_mod = factor_one_table.replace('',str(0))
            list_one_table_situ.append(one_table_mod)
        dic_one_table = dict(zip(list_one_table, list_one_table_situ))
        jp_dic_one_table = dic_one_table.copy()
        time_dic_one_table = dic_one_table.copy()
        for i in jp_dic_one_table:
            jp_dic_one_table[i] = 'Vacant'

    # Assign names and create dictionaries 
    def all_situ_table(self):
        self.situ_four_table()
        self.situ_two_table()
        self.situ_one_table()
        message.showinfo("Registration Success","Seat data has been successfully registered")
        self.quit_window_bs()

    # Change seat situation
    def change_table_situ(self): 
        global dic_four_table
        global dic_two_table
        global dic_one_table
        global jp_dic_four_table
        global jp_dic_two_table
        global jp_dic_one_table
        if list_four_table == [] and list_two_table == [] and list_one_table == []:
            message.showerror("Error","Type in seat number from 'Register Number of Seats' on Home Screen")
            self.quit_window_bc()
        else:
            try:
                table_type = int(entry_table_type.get())
                table_num = int(entry_table_num.get())-1
                table_situ = int(entry_table_situ.get())
                if table_type == 4:
                    table_name=list_four_table[table_num]
                    try:
                        dic_four_table[table_name] = str(table_situ)
                        message.showinfo("Change Success","Seat situation has been successfully changed")
                        for i in jp_dic_four_table:
                            if jp_dic_four_table[i] == "0":
                                jp_dic_four_table[i] = "Vacant"
                            elif jp_dic_four_table[i] == "1":
                                jp_dic_four_table[i] = "Wait for order"
                            elif jp_dic_four_table[i] == "2":
                                jp_dic_four_table[i] = "Wait for dish serve"
                            elif jp_dic_four_table[i] == "3":
                                jp_dic_four_table[i] = "Dish served"
                        self.quit_window_bc()
                    except ValueError:
                        message.showerror("Error","Can't change to integer. Try again")
                    except:
                        message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again")  
                elif table_type == 2:
                    try:
                        table_name=list_two_table[table_num]
                        dic_two_table[table_name] = str(table_situ)
                        message.showinfo("Change Success","Seat situation has been successfully changed")
                        for i in jp_dic_two_table:
                            if jp_dic_two_table[i] == "0":
                                jp_dic_two_table[i] = "Vacant"
                            elif jp_dic_two_table[i] == "1":
                                jp_dic_two_table[i] = "Wait for order"
                            elif jp_dic_two_table[i] == "2":
                                jp_dic_two_table[i] = "Wait for dish serve"
                            elif jp_dic_two_table[i] == "3":
                                jp_dic_two_table[i] = "Dish served"
                        self.quit_window_bc()
                    except ValueError:
                        message.showerror("Error","Can't change to integer. Try again")
                    except:
                        message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again") 
                elif table_type == 1:
                    try:
                        table_name=list_one_table[table_num]
                        dic_one_table[table_name] = str(table_situ)
                        message.showinfo("Change Success","Seat situation has been successfully changed")
                        for i in jp_dic_one_table:
                            if jp_dic_one_table[i] == "0":
                                jp_dic_one_table[i] = "Vacant"
                            elif jp_dic_one_table[i] == "1":
                                jp_dic_one_table[i] = "Wait for order"
                            elif jp_dic_one_table[i] == "2":
                                jp_dic_one_table[i] = "Wait for dish serve"
                            elif jp_dic_one_table[i] == "3":
                                jp_dic_one_table[i] = "Dish served"
                        self.quit_window_bc()
                    except ValueError:
                        message.showerror("Error","Can't change to integer. Try again")
                    except:
                        message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again") 
                    else:
                        message.showerror("Error",'Please type in 4 or 2 or 1')
            except ValueError:
                message.showerror("Error","Can't change to integer. Try again")
            except:
                message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again")        

    # Add custumer to the queue
    def add_wait_que(self):
        global wait_que
        global add_que
        try: 
            add_que =int(entry_add_que.get())
            if add_que <=4:
                wait_que.append(add_que)
                message.showinfo("Registration Success", "Data has been successfully registered.")
                self.quit_window_ba()
            else:
                message.showerror("Error","If there are more than 5 people, divide them into two groups, so that each group has no more than 4 people.")
                self.add_wait_que()
        except ValueError:
            message.showerror("Error","Can't change to integer. Try again")
        except:
            message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again")      

    # if there is no que, will use this function
    def add_table_wait_time(self):
        global time_dic_four_table
        global time_dic_two_table
        global time_dic_one_table
        for i in dic_one_table:
            if dic_one_table[i] == "0":
                time_dic_one_table[i] = str(0)
            elif dic_one_table[i] == "1":
                time_dic_one_table[i] = str(50)
            elif dic_one_table[i] == "2":
                time_dic_one_table[i] = str(40)
            elif dic_one_table[i] == "3":
                time_dic_one_table[i] = str(15)
        for i in dic_two_table:
            if dic_two_table[i] == "0":
                time_dic_two_table[i] = str(0)
            elif dic_two_table[i] == "1":
                time_dic_two_table[i] = str(50)
            elif dic_two_table[i] == "2":
                time_dic_two_table[i] = str(40)
            elif dic_two_table[i] == "3":
                time_dic_two_table[i] = str(15)
        for i in dic_four_table:
            if dic_four_table[i] == "0":
                time_dic_four_table[i] = str(0)
            elif dic_four_table[i] == "1":
                time_dic_four_table[i] = str(50)
            elif dic_four_table[i] == "2":
                time_dic_four_table[i] = str(40)
            elif dic_four_table[i] == "3":
                time_dic_four_table[i] = str(15)
    
    # Show waiting time
    def show_wait_time(self):
        global screen_br
        try:
            wait_num = int(entry_br.get())
            self.add_table_wait_time()
            if wait_que == []:
                if wait_num == 1:
                    message.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_one_table.values())+'minutes')
                elif wait_num == 2:
                    message.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_two_table.values())+'minutes')
                elif wait_num == 3 or wait_num == 4:
                    message.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_four_table.values())+'minutes')
                self.quit_window_br()
            else: #If there is a queue
                if wait_que[wait_num-1] == 1:
                    for i in range(wait_num-1):
                        if wait_que[i] == 1:
                            table_key = min(time_dic_one_table)
                            time_dic_one_table[table_key] = str(int(time_dic_one_table[table_key]) + 50)
                    messege.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_one_table.values())+'minutes')
                elif wait_que[wait_num-1] == 2:
                    for i in range(wait_num-1):
                        if wait_que[i] == 2:
                            table_key = min(time_dic_two_table)
                            time_dic_two_table[table_key] = str(int(time_dic_two_table[table_key]) + 50)
                    message.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_two_table.values())+'minutes')
                elif wait_que[wait_num-1] == 3 or wait_que[wait_num-1] == 4:
                    for i in range(wait_num-1):
                        if wait_que[i] == 3 or wait_que[i] == 4:
                            table_key = min(time_dic_four_table)
                            time_dic_four_table[table_key] = str(int(time_dic_four_table[table_key]) + 50)
                    message.showinfo("Waiting Time", 'Your waiting time is'+min(time_dic_four_table.values())+'minutes')
                self.quit_window_br()
        except ValueError:
            message.showerror("Error","Can't change to integer. Try again")
        except:
            message.showerror("Error","Unexpected Error. Make sure that seat really exists and try again") 
            
root = tk.Tk()
f = MainFrame(root)
f.pack()
f.mainloop()

I'm new to programming and not a native English speaker so this may sound weird, but I appreciate your advice!

\$\endgroup\$
1
  • \$\begingroup\$ You code too complicated to review. It also mixes UI and Business logic. It also uses globals. Watch this youtu.be/eHhXoCNCI1c?si=943IW4DFV6-EFguC and try applying MVP pattern mentioned in the video. The presenter also uses TKinter so should be a good fit. \$\endgroup\$ Dec 7, 2023 at 20:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.