-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTable.py
More file actions
62 lines (50 loc) · 1.69 KB
/
Copy pathTable.py
File metadata and controls
62 lines (50 loc) · 1.69 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
import tkinter as tk
from tkinter import ttk
import mysql.connector
import os
from dotenv import load_dotenv
def fetch_data():
try:
# Establish connection to MySQL database
mydb = mysql.connector.connect(
host=os.getenv("HOST"),
user=os.getenv("USER"),
password=os.getenv("PASSWORD"),
database=os.getenv("DATABASE")
)
mycursor = mydb.cursor()
# Execute query to retrieve data from the table
mycursor.execute("SELECT email, password FROM signup")
# Fetch all rows from the result set
rows = mycursor.fetchall()
return rows
except mysql.connector.Error as e:
print("Error fetching data:", e)
return None
def display_data():
# Fetch data from the database
data = fetch_data()
if data:
# Clear existing data in the Treeview widget
for row in table.get_children():
table.delete(row)
# Insert fetched data into the Treeview widget
for row in data:
table.insert('', 'end', values=row)
root = tk.Tk()
root.title('USERS DATA')
root.geometry('925x500')
root.configure(bg="#fff")
root.resizable(False, False)
# Treeview
table = ttk.Treeview(root, columns=('email', 'passwd'), show='headings')
table.heading('email', text='Email address')
table.heading('passwd', text='Password ')
table.column('email', width=400)
table.column('passwd', width=400)
# Pack the Treeview widget to fill the entire height of the window
table.pack(fill='both', expand=True)
# Connect to database and display data
display_data()
# Run the Tkinter main event loop
root.mainloop()