Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sample

# 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,'
')
    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, '
')
    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.
Prod. Name.
Prod. 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()
Comment

PREVIOUS NEXT
Code Example
Python :: Python Map Function Syntax 
Python :: django drf 
Python :: setup vs code for python 
Python :: site:*.instagram.com 
Python :: get column names and and index dataframe 
Python :: take union of two dataframes pandas 
Python :: sys.argv python example 
Python :: pivot tables pandas explicación 
Python :: librosa from array to audio 
Python :: Adding column to CSV Dictreader 
Python :: transcript with timestamps in python 
Python :: Search for a symmetrical inner elements of a list python 
Python :: Simple Kivy pong game 
Python :: doormat pattern python 
Python :: python hlaf of list 
Python :: how to make a window in python ursina 
Python :: python glob sort numerically 
Python :: python you bad 
Python :: python deep setter 
Python :: #clearing all keys new key in python 
Python :: numpy create array with infinities 
Python :: Cannot seem to use import time and import datetime in same script in Python 
Python :: sum of two diagonals in matrix 
Python :: matplotlib share colorbar 
Python :: image.get p5 
Python :: find mising number in O(n) 
Python :: python web app with redis github 
Python :: pylint no name in module opencv 
Python :: spyder - identation 
Python :: python difference between multiprocessing pool and threadpool 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =