· 6 years ago · Oct 09, 2019, 10:06 AM
1import sqlite3 as sq
2import tkinter as tk
3
4conn = sq.connect('demo.db')
5c = conn.cursor()
6
7# c.execute('DROP TABLE IF EXISTS "scenes";')
8
9c.execute("""
10 CREATE TABLE IF NOT EXISTS "scenes" (
11 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
12 "scene_name" TEXT NOT NULL,
13 "scene_description" TEXT NOT NULL
14 );
15""")
16
17
18def add_to_db():
19 s = scene_name.get(1.0, tk.END).strip()
20 d = scene_description.get(1.0, tk.END).strip()
21 print(s, d)
22 c.execute('INSERT INTO scenes ("scene_name", "scene_description") VALUES (?,?);', (s,d))
23 conn.commit()
24 scene_name.delete(1.0, tk.END)
25 scene_description.delete(1.0, tk.END)
26 scene_name.focus()
27
28
29
30master = tk.Tk()
31master.title("Tkinter Demo")
32master.geometry('800x600+100+50')
33header = tk.Label(master, text="Adventure Game Builder", font=("arial",30,"bold"), fg="steelblue").pack()
34
35
36scene_name_width = 40
37scene_name_height = 1
38scene_description_width = 40
39scene_description_height = 5
40
41tk.Label(master,
42 text="Enter scene name", font=("arial",12,"normal"), fg="grey").pack()
43scene_name = tk.Text(master, width=scene_name_width, height=scene_name_height, wrap=tk.WORD)
44scene_name.pack()
45
46tk.Label(master,
47 text="Enter scene description", font=("arial",12,"normal"), fg="grey").pack()
48
49scene_description = tk.Text(master, width=scene_description_width, height=scene_description_height, wrap=tk.WORD)
50scene_description.pack()
51
52tk.Button(master,
53 text='Quit',
54 command=master.destroy).pack()
55tk.Button(master,
56 text='Save', command=add_to_db).pack()
57
58tk.mainloop()
59conn.close()