Tài Khoản Khách
ngày 27 tháng 6 năm 2023
import tkinter as tk import sqlite3 def add_to_cart(): item_name = item_name_entry.get() quantity = quantity_entry.get() email = email_entry.get() conn = sqlite3.connect("mobile.db") cursor = conn.cursor() cursor.execute("CREATE TABLE IF NOT EXISTS mobile_cart(item_name TEXT, email TEXT , quantity INTEGER)") cursor.execute("INSERT INTO mobile_cart VALUES (?,?,?)", (item_name, email, quantity)) conn.commit() conn.close() def delete_selected(): selection = mobile_list_text.curselection() if selection: index = selection[0] item = mobile_list[index] conn = sqlite3.connect("mobile.db") cursor = conn.cursor() cursor.execute("DELETE FROM mobile_cart WHERE item_name=? AND email=? AND quantity=?", item) conn.commit() conn.close() mobile_list_text.delete(index) # Удаление выбранного элемента из списка def show_mobile_list(): conn = sqlite3.connect('mobile.db') cursor = conn.cursor() cursor.execute("SELECT * FROM mobile_cart") global mobile_list mobile_list = cursor.fetchall() conn.close() window = tk.Toplevel() window.title("Список покупок") window.geometry("600x400") # Новые размеры окна: ширина 600, высота 400 global mobile_list_text mobile_list_text = tk.Listbox(window, width=50, height=20) # Увеличьте ширину и высоту списка mobile_list_text.pack() delete_button = tk.Button(window, text="Удалить", command=delete_selected, width=20) delete_button.pack() for item in mobile_list: item_name = item[0] quantity = item[2] email = item[1] mobile_list_text.insert(tk.END, f"ФИО: {item_name}, email: {email}\n Телефон: {quantity}\n") def main(): global item_name_entry, quantity_entry, email_entry window = tk.Tk() window.title("Список покупок") window.geometry('400x200') item_name_label = tk.Label(window, text="ФИО:") item_name_label.pack() item_name_entry = tk.Entry(window) item_name_entry.pack() quantity_label = tk.Label(window, text="Телефон:") quantity_label.pack() quantity_entry = tk.Entry(window) quantity_entry.pack() email_label = tk.Label(window, text="Email:") email_label.pack() email_entry = tk.Entry(window) email_entry.pack() add_to_cart_button = tk.Button(window, text="Добавить в список", command=add_to_cart) add_to_cart_button.pack() show_list_button = tk.Button(window, text="Просмотреть список", command=show_mobile_list) show_list_button.pack() window.mainloop() if __name__ == '__main__': main()
Dịch