· 9 years ago · Dec 21, 2016, 03:16 AM
1from tkinter import *
2import tkinter.messagebox
3
4fenster = Tk() # create a window
5fenster.title("Telefonbuch") #title of window
6fenster.geometry("250x200") #size of window
7
8
9import sqlite3
10
11conn = sqlite3.connect('epr05.db')
12
13c = conn.cursor()
14
15
16
17
18def createtable(): # create a new table
19 c.execute("CREATE TABLE IF NOT EXISTS telephonbook(firstname TEXT, lastname TEXT, street TEXT, plz INT, city TEXT, telephonnr INT)")
20
21createtable()
22
23def inputdata(): # data input in phonebook
24 c.execute("INSERT INTO telephonbook VALUES('BANJULUU','Müller','',77777,'Sevenstadt',756483928888)")
25 c.execute('SELECT * FROM telephonbook')
26 a = ""
27 for row in c.fetchall():
28 a += str(row) + "\n"
29 tkinter.messagebox.showinfo("Telephonbook with new inputted data",a)
30 conn.commit()
31
32def showtabledata(): # show the phonebook
33 c.execute('SELECT * FROM telephonbook')
34 a = ""
35 for row in c.fetchall():
36 a += str(row) + "\n"
37 tkinter.messagebox.showinfo("Telephonbook",a)
38
39
40def searchdata(): # show searched data only from phonebook
41 c.execute('SELECT * FROM telephonbook WHERE firstname = "Hannah"')
42 a = ""
43 for row in c.fetchall():
44 a += str(row) + "\n"
45 tkinter.messagebox.showinfo("Search Data",a)
46
47
48def showsorttabledata(): # sort table and show it
49 c.execute('SELECT * FROM telephonbook ORDER BY telephonnr DESC')
50 a = ""
51 for row in c.fetchall():
52 a += str(row) + "\n"
53 tkinter.messagebox.showinfo("Sorted Telephonbook",a)
54
55
56
57def deletdata(): # deletes the datas u choose
58 x = c.execute("DELETE FROM telephonbook WHERE firstname = 'Sandra'")
59 c.execute('SELECT * FROM telephonbook')
60 a = ""
61 for row in c.fetchall():
62 a += str(row) + "\n"
63 tkinter.messagebox.showinfo("Telephonbook without deleted data",a)
64 conn.commit()
65
66def updatedata(): # update datas from table
67 c.execute("UPDATE telephonbook SET firstname = 'SAMUELLL' WHERE firstname = 'Samuel'")
68 c.execute('SELECT * FROM telephonbook')
69 a = ""
70 for row in c.fetchall():
71 a += str(row) + "\n"
72 tkinter.messagebox.showinfo("Updated Data",a)
73 conn.commit()
74
75
76
77def gethelp (): #getting help
78 output ="Press 'display' when u want to see the whole telephonbook. "
79 output +="Press 'search' when u want to see only the things which are searched. "
80 output +="Press 'sort' to see the sorted whole telephonbook. "
81 output +="Press 'change' to create a change in the telephonbook and show the telephonbook with the change. "
82 output +="Press 'delete'to delete data from the telephonbook and show the rest of the telephonbook. "
83 output +="Press 'input' to input new data to the telephonbook and show the new telephonbook. "
84 tkinter.messagebox.showinfo("Help",output)
85
86showdata = Button(text="display",command=showtabledata) # erzeugen von Buttons
87showdata.pack()
88search = Button(text="search",command=searchdata)
89search.pack()
90sortdata = Button(text="sort",command=showsorttabledata)
91sortdata.pack()
92changedata = Button(text="change",command=updatedata)
93changedata.pack()
94deletedata = Button(text="delete",command=deletdata)
95deletedata.pack()
96inputdata = Button(text="input" ,command=inputdata)
97inputdata.pack()
98gethelp = Button(text="Press here when u need help!",command=gethelp)
99gethelp.pack()
100
101
102
103
104
105
106conn.commit()
107mainloop()
108c.close()
109conn.close()