Hello everyone I am writing a small program for sorting goods, the program is already ready in the console version, but I would like to implement it in a graphical version. The essence of the problem: I'm sitting at what time and thinking how to implement pop-up windows with text input for this part of the code. I will be grateful for your help. here is the code:
def add_product(self, instance): code = input("Введите код товара: ") category_code = input("Введите код категории товара: ") name = input("Введите наименование товара: ") description = input("Введите описание товара: ") price = float(input("Введите цену товара: ")) quantity = int(input("Введите количество товара: ")) popup = Popup(title='Добавить товар', content=content, size_hint=(None, None), size=(400, 400)) popup.open() cursor.execute("INSERT INTO products VALUES (?, ?, ?, ?, ?, ?)", (code, category_code, name, description, price, quantity)) conn.commit() # Удаление товара def delete_product(self, instance): code = input("Введите код товара для удаления: ") popup = Popup(title='Удалить товар', content=content, size_hint=(None, None), size=(400, 400)) popup.open() cursor.execute("DELETE FROM products WHERE code=?", (code,)) conn.commit() # Корректировка товара def edit_product(self, instance): code = input("Введите код товара для корректировки: ") cursor.execute("SELECT * FROM products WHERE code=?", (code,)) product = cursor.fetchone() if product is not None: print("Текущая информация о товаре:") print(product) popup = Popup(title='Изменить товар', content=content, size_hint=(None, None), size=(400, 400)) popup.open() # Ввод новых значений для товара new_code = input("Введите новый код товара: ") popup = Popup(title='Введите новый код товара:', content=content, size_hint=(None, None), size=(400, 400)) popup.open() new_category_code = input("Введите новый код категории товара: ") new_name = input("Введите новое наименование товара: ") new_description = input("Введите новое описание товара: ") new_price = float(input("Введите новую цену товара: ")) new_quantity = int(input("Введите новое количество товара: ")) # Обновление записи в базе данных cursor.execute("UPDATE products SET code=?, category_code=?, name=?, description=?, price=?, quantity=? WHERE code=?", (new_code, new_category_code, new_name, new_description, new_price, new_quantity, code)) conn.commit() print("Информация о товаре успешно обновлена.") # Поиск товара по наименованию и модели def search_product(self, instance): search_term = input("Введите наименование или модель товара для поиска: ") cursor.execute("SELECT * FROM products WHERE name LIKE ? OR description LIKE ?", (f"%{search_term}%", f"%{search_term}%")) products = cursor.fetchall() if products: print("Результаты поиска:") for product in products: print(product) else: print("Товар не найден.") # Сортировка товаров по коду, цене и имени def sort_products(self, instance): sort_option = input("Выберите опцию сортировки (code, price, name): ") cursor.execute(f"SELECT * FROM products ORDER BY {sort_option}") products = cursor.fetchall() if products: print("Отсортированный список товаров:") for product in products: print(product) else: print("Список товаров пуст.")
Here's what I tried:
def show_add_product(self, instance):
content = BoxLayout(orientation='vertical')
code_input = TextInput(hint_text='Код товара')
content.add_widget(code_input)
category_code_input = TextInput(hint_text='Код категории товара')
content.add_widget(category_code_input)
name_input = TextInput(hint_text='Наименование товара')
content.add_widget(name_input)
description_input = TextInput(hint_text='Описание товара')
content.add_widget(description_input)
price_input = TextInput(hint_text='Цена товара')
content.add_widget(price_input)
quantity_input = TextInput(hint_text='Количество товара')
content.add_widget(quantity_input)
add_button = Button(text='Добавить', size_hint=(None, None), size=(100, 50))
content.add_widget(add_button)
def add_product(instance):
code = code_input.text
category_code = category_code_input.text
name = name_input.text
description = description_input.text
price = float(price_input.text)
quantity = int(quantity_input.text)
cursor.execute("INSERT INTO products VALUES (?, ?, ?, ?, ?, ?)",
(code, category_code, name, description, price, quantity))
conn.commit()
popup.dismiss()
add_button.bind(on_press=add_product)
popup = Popup(title='Добавить товар', content=content, size_hint=(None, None), size=(400, 400))
popup.open()
But the add button does not respond