-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (41 loc) · 1.14 KB
/
main.py
File metadata and controls
58 lines (41 loc) · 1.14 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
import tkinter as tk
import sqlite3
app = tk.Tk()
app.title("Python Desktop App")
app.geometry("400x300")
def update_listbox():
conn = sqlite3.connect("names.db")
c = conn.cursor()
c.execute("SELECT * FROM names")
rows = c.fetchall()
listbox.delete(0, tk.END)
for row in rows:
listbox.insert(tk.END, row[1])
conn.close()
listbox = tk.Listbox(app)
listbox.pack()
def create_database():
conn = sqlite3.connect("names.db")
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS names (
id INTEGER PRIMARY KEY,
name TEXT
)""")
conn.commit()
conn.close()
update_listbox()
create_database()
def on_submit():
name = entry.get()
conn = sqlite3.connect("names.db")
c = conn.cursor()
c.execute("INSERT INTO names (name) VALUES (?)", (name,))
conn.commit()
conn.close()
label = tk.Label(app, text="Enter your name:")
label.pack()
entry = tk.Entry(app)
entry.pack()
submit_button = tk.Button(app, text="Submit", command=on_submit)
submit_button.pack()
app.mainloop()