próbka

# import libraries (i use as tk to reduce the full import on launch)
import tkinter as tk

client_orders = [] # List of orders

def new_order_popup():
    new_order_window.deiconify() # used to open the new order window (toplevel window)

class NEW_ORDER: # new order class, simplified for example)
    def __init__(self, product_num, product_name, product_price):
        self.product_num = product_num
        self.product_name = product_name
        self.product_price = product_price


def new_order(product_num, product_name, product_price): # creates each new order when 
called.
    new_order_window.deiconify()
    input_product_num = pro_num_entry.get()
    input_product_name = pro_name_entry.get()
    input_product_price = float(pro_price_entry.get())

    newOrder = NEW_ORDER(input_product_num, input_product_name, input_product_price)
    return newOrder


def sub_(): # action when button pressed for submit/save

    customer_order = new_order(product_num=str, product_name=str, product_price=float)
    price_str = str(customer_order.product_price)
    client_orders.append(customer_order)
    order_string = (customer_order.product_num,' : ', customer_order.product_name,' : 
    ', price_str,'\n')
    print(order_string)
    txt_file = open(f'text_doc.txt', 'a')
    txt_file.writelines(order_string)
    txt_file.close()


def sub_ex(): # same as other button but closes toplevel window.
    customer_order = new_order(product_num=str, product_name=str, product_price=float)
    price_str = str(customer_order.product_price)
    client_orders.append(customer_order)
    order_string = (customer_order.product_num, ' : ', customer_order.product_name, ' 
    : ', price_str, '\n')
    print(order_string)

    txt_file = open(f'text_doc.txt', 'a')
    txt_file.writelines(order_string)
    txt_file.close()
    new_order_window.withdraw()

#main window tkinter  code.  (at bottom eleviates complicated poiubters abd calls)
main = tk.Tk()

main.geometry('300x100')
main.title('Some Ordering System')
#button that does something
new_order_button = tk.Button(main)
new_order_button.configure(text='NewOrder', command = lambda: new_order_popup())
new_order_button.pack(pady=25)

#secondary window
new_order_window = tk.Toplevel(main)
new_order_window.geometry('300x200')
new_order_window.withdraw()

list_label = tk.Label(new_order_window)
list_label.configure(text='Prod. Num.\nProd. Name.\nProd. Price.')
list_label.place(anchor=tk.NW, x=15, y=15)

pro_num_entry = tk.Entry(new_order_window)
pro_num_entry.configure(width=20)
pro_num_entry.place(anchor=tk.NW, x=100, y=15)

pro_name_entry = tk.Entry(new_order_window)
pro_name_entry.configure(width=20)
pro_name_entry.place(anchor=tk.NW, x=100, y=35)

pro_price_entry = tk.Entry(new_order_window)
pro_price_entry.configure(width=20)
pro_price_entry.place(anchor=tk.NW, x=100, y=55)

submit_button = tk.Button(new_order_window)

submit_button.configure(text='Submit', command = lambda: sub_())
submit_button.place(anchor=tk.NW, x=35, y=100)

submit_exit_button = tk.Button(new_order_window)

submit_exit_button.configure(text='Submit and exit', command = lambda: sub_ex())
submit_exit_button.place(anchor=tk.NW, x=100, y=100)

main.mainloop()
Gopal Patel