-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathexample-1.py
More file actions
69 lines (43 loc) · 1.47 KB
/
Copy pathexample-1.py
File metadata and controls
69 lines (43 loc) · 1.47 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
#!/usr/bin/env python3
import tkinter as tk
import tkinter.ttk as ttk
import sqlite3
class Example:
def __init__(self,master):
self.master = master
self.db = sqlite3.connect('database.db')
tk.Label(master, text='All:').pack()
self.cb = ttk.Combobox(master)
self.cb.pack()
self.cb['values'] = self.get_data()
tk.Label(master, text='P:').pack()
self.cb_p = ttk.Combobox(master)
self.cb_p.pack()
self.cb_p['values'] = self.get_data('p')
def get_data(self, where=None):
cursor = self.db.cursor()
# COLLATE NOCASE - sort case insensitive
if where:
cursor.execute("SELECT item FROM stocks WHERE item LIKE ? ORDER BY item COLLATE NOCASE ASC", (where+'%',))
else:
cursor.execute('SELECT item FROM stocks ORDER BY item COLLATE NOCASE ASC')
data = []
for row in cursor.fetchall():
data.append(row[0])
cursor.close()
return data
# --- functions ---
def create_db():
data = ['Hello', 'World', 'Python', 'tkinter', 'pandas', 'pygame', 'requests']
db = sqlite3.connect('database.db')
cursor = db.cursor()
cursor.execute('CREATE TABLE stocks (id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT)')
for word in data:
cursor.execute('INSERT INTO stocks (item) VALUES(?)', (word,))
cursor.close()
db.commit()
# --- main ---
#create_db()
root = tk.Tk()
Example(root)
root.mainloop()