def render_login(error=None): clean_screen() username = Entry(tk) username.grid(row=0, column=0) password = Entry(tk) password.grid(row=1, column=0) if error is not None: Label(tk, text="Invalid username or password").grid(row=3, column=0) Button(tk, text="Enter", bg="green", command=lambda: login(username.get(), password.get())).grid( row=2, column=0)
def render_products(): clean_screen() with open("db/products.txt", "r") as file: products = file.readlines() col = 0 for product in products: current_product = json.loads(product) Label(text=current_product.get('name')).grid(row=0, column=col) image = Image.open(os.path.join(os.path.join(base_folder, 'images'), current_product.get('img_path'))) image = image.resize((100, 100)) photo = ImageTk.PhotoImage(image) img_label = Label(image=photo) img_label.image = photo img_label.grid(row=1, column=col) Button(tk, text=f"Buy {current_product.get('id')}").grid(row=2, column=col) col += 1
def render_register(): clean_screen() username = Entry(tk) username.grid(row=0, column=0) password = Entry(tk) password.grid(row=1, column=0) first_name = Entry(tk) first_name.grid(row=2, column=0) last_name = Entry(tk) last_name.grid(row=3, column=0) # Make validations for names lenght and username to be unique and with no special chars Button(tk, text="Register", bg="green", command=lambda: register(username=username.get(), password=password.get(), first_name=first_name.get(), last_name=last_name.get())).grid(row=4, column=0)
def render_register_form(): clean_screen() Label(tk, text="Username").grid(row=0, column=0) username = Entry(tk) username.grid(row=0, column=1) Label(tk, text="Password").grid(row=1, column=0) password = Entry(tk) password.grid(row=1, column=1) Label(tk, text="First Name").grid(row=2, column=0) first_name = Entry(tk) first_name.grid(row=2, column=1) Label(tk, text="Last Name").grid(row=3, column=0) last_name = Entry(tk) last_name.grid(row=3, column=1) Button(tk, text="Register", bg="green", command=lambda: register(username=username.get(), password=password.get(), first_name=first_name.get(), last_name=last_name.get())).grid(row=4, column=1)
def render_products(): clean_screen() with open('db/products.txt', 'r') as file: products = file.readlines() col_counter = 0 for product in products: current_product = json.loads(product) Label(text=current_product.get('name')).grid(row=0, column=col_counter) image = Image.open( os.path.join(os.path.join(base_folder, 'images'), current_product.get('img_path'))) image = image.resize((100, 100)) photo = ImageTk.PhotoImage(image) img_label = Label(image=photo) img_label.image = photo img_label.grid(row=1, column=col_counter) button = Button(tk, text=f'Buy {current_product.get("id")}') button.configure(command=lambda b=button: buy_product(b)) button.grid(row=3, column=col_counter) Label(text=current_product.get('count')).grid(row=2, column=col_counter) col_counter += 1