-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStockMarketMaintain.py
More file actions
71 lines (57 loc) · 2.03 KB
/
Copy pathStockMarketMaintain.py
File metadata and controls
71 lines (57 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import tkinter as tk
import sqlite3
# Database initialization
conn = sqlite3.connect("stock.db")
cur = conn.cursor()
# Create table if it doesn't exist
cur.execute("CREATE TABLE IF NOT EXISTS stock (item TEXT, quantity INTEGER)")
# Function to add an item to the stock
def add_item():
item = item_entry.get()
quantity = int(quantity_entry.get())
cur.execute("INSERT INTO stock VALUES (?, ?)", (item, quantity))
conn.commit()
status_label.config(text="Item added successfully.")
# Function to display all items in the stock
def display_items():
cur.execute("SELECT * FROM stock")
items = cur.fetchall()
if items:
for item in items:
print(item)
else:
print("No items in stock.")
# Function to delete an item from the stock
def delete_item():
item = item_entry.get()
cur.execute("DELETE FROM stock WHERE item=?", (item,))
conn.commit()
status_label.config(text="Item deleted successfully.")
# GUI initialization
root = tk.Tk()
root.title("Super Market Stock Maintenance System")
# Item Label and Entry
item_label = tk.Label(root, text="Item:")
item_label.grid(row=0, column=0, padx=10, pady=10)
item_entry = tk.Entry(root)
item_entry.grid(row=0, column=1, padx=10, pady=10)
# Quantity Label and Entry
quantity_label = tk.Label(root, text="Quantity:")
quantity_label.grid(row=1, column=0, padx=10, pady=10)
quantity_entry = tk.Entry(root)
quantity_entry.grid(row=1, column=1, padx=10, pady=10)
# Add Button
add_button = tk.Button(root, text="Add Item", command=add_item)
add_button.grid(row=2, column=0, padx=10, pady=10)
# Display Button
display_button = tk.Button(root, text="Display Items", command=display_items)
display_button.grid(row=2, column=1, padx=10, pady=10)
# Delete Button
delete_button = tk.Button(root, text="Delete Item", command=delete_item)
delete_button.grid(row=2, column=2, padx=10, pady=10)
# Status Label
status_label = tk.Label(root, text="")
status_label.grid(row=3, column=0, columnspan=3, padx=10, pady=10)
root.mainloop()
# Close database connection
conn.close()