-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataView.py
95 lines (76 loc) · 2.9 KB
/
dataView.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 16 10:47:04 2020
@author: sezginmuslu
"""
import sys
if "Tkinter" not in sys.modules:
import tkinter as tk
from tkinter.ttk import *
import mysql.connector
import databasefile as dbb
import screens.startScreen as stc
class dataView(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
mydb = dbb.connecttodb()
crs = mydb.cursor()
que = "SELECT * FROM student"
crs.execute(que)
al = crs.fetchall()
btn = tk.Button(self, text = "back", command= lambda: controller.show_frame(stc.StartPage))
tv = Treeview(self)
tv['columns'] = ('Name', 'Surname', 'email','phone')
tv.heading("#0", text='Tc', anchor='w')
tv.column("#0", anchor="w")
tv.heading('Name', text='Name')
tv.column('Name', anchor='center', width=100)
tv.heading('Surname', text='Surname')
tv.column('Surname', anchor='center', width=100)
tv.heading('email', text='email')
tv.column('email', anchor='center', width=100)
tv.heading('phone', text='phone')
tv.column('phone', anchor='center', width=100)
tv.grid(sticky = (tk.N,tk.S,tk.W,tk.E))
self.treeview = tv
self.grid_rowconfigure(0, weight = 1)
self.grid_columnconfigure(0, weight = 1)
btn.grid(row = 1,column=1)
cpt = 0 # Counter representing the ID of your code.
for row in al:
# I suppose the first column of your table is ID
tv.insert('', 'end', text=str(row[0]), values=(row[1], row[2], row[3],row[4]))
cpt += 1 # increment the ID
crs.close()
mydb.close()
# def viewData():
# root = Tk()
# mydb = dbb.connecttodb()
# crs = mydb.cursor()
# que = "SELECT * FROM student"
# crs.execute(que)
# al = crs.fetchall()
# tv = Treeview(root)
# tv['columns'] = ('Name', 'Surname', 'email','phone')
# tv.heading("#0", text='Tc', anchor='w')
# tv.column("#0", anchor="w")
# tv.heading('Name', text='Name')
# tv.column('Name', anchor='center', width=100)
# tv.heading('Surname', text='Surname')
# tv.column('Surname', anchor='center', width=100)
# tv.heading('email', text='email')
# tv.column('email', anchor='center', width=100)
# tv.heading('phone', text='phone')
# tv.column('phone', anchor='center', width=100)
# tv.grid(sticky = (N,S,W,E))
# root.treeview = tv
# root.grid_rowconfigure(0, weight = 1)
# root.grid_columnconfigure(0, weight = 1)
# cpt = 0 # Counter representing the ID of your code.
# for row in al:
# # I suppose the first column of your table is ID
# tv.insert('', 'end', text=str(row[0]), values=(row[1], row[2], row[3],row[4]))
# cpt += 1 # increment the ID
# crs.close()
# mydb.close()
# root.mainloop()