-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.py
More file actions
72 lines (58 loc) · 2.21 KB
/
insert.py
File metadata and controls
72 lines (58 loc) · 2.21 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
72
import tkinter as tk
from tkinter import messagebox
from connection import get_connection
# Συνάρτηση για εισαγωγή αυτοκινήτου
from connection import get_connection
def insert_car(model, year, color):
connection = get_connection()
cursor = connection.cursor()
sql = "INSERT INTO cars (model, year, color) VALUES (%s, %s, %s)"
values = (model, year, color)
cursor.execute(sql, values)
connection.commit()
print("Car added.")
cursor.close()
connection.close()
return True
except Exception as e:
print("Σφάλμα:", e)
return False
# Συνάρτηση για χειρισμό του κουμπιού
def submit_car():
model = model_title.get()
year = entry_year.get()
color = entry_color.get()
if not (model and year and color):
messagebox.showwarning("Σφάλμα", "Συμπλήρωσε όλα τα πεδία!")
return
try:
year = int(year)
except ValueError:
messagebox.showerror("Σφάλμα", "Το έτος πρέπει να είναι αριθμός!")
return
if insert_car(model, year, color):
messagebox.showinfo("Επιτυχία", "Το αυτοκίνητο προστέθηκε επιτυχώς!")
entry_model.delete(0, tk.END)
entry_year.delete(0, tk.END)
entry_color.delete(0, tk.END)
else:
messagebox.showerror("Αποτυχία", "Αποτυχία εισαγωγής αυτοκινήτου.")
# Δημιουργία παραθύρου
window = tk.Tk()
window.title("Εισαγωγή Αυτοκινήτου")
window.geometry("400x300")
# Ετικέτες και πεδία
tk.Label(window, text="Μοντέλο:").pack(pady=5)
entry_model = tk.Entry(window, width=40)
entry_model.pack()
tk.Label(window, text="Χρονολογία:").pack(pady=5)
entry_year = tk.Entry(window, width=40)
entry_year.pack()
tk.Label(window, text="Χρώμα:").pack(pady=5)
entry_color = tk.Entry(window, width=40)
entry_color.pack()
# Κουμπί καταχώρησης
submit_button = tk.Button(window, text="Καταχώρηση Αυτοκινήτου", command=submit_book)
submit_button.pack(pady=20)
# Εκκίνηση εφαρμογής
window.mainloop()