-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (85 loc) · 3.42 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import tkinter as tk
from tkinter import ttk
import openpyxl
def load_data():
path = "E:\CU WORK\#myprojects\python-excel-app\people.xlsx"
workbook = openpyxl.load_workbook(path)
sheet = workbook.active
list_values = list(sheet.values)
print(list_values)
for col_name in list_values[0]:
treeview.heading(col_name, text=col_name)
for value_tuple in list_values[1:]:
treeview.insert('', tk.END, values=value_tuple)
def insert_row():
name = name_entry.get()
age = int(age_spinbox.get())
subscription_status = status_combobox.get()
employment_status = "Employed" if a.get() else "Unemployed"
print(name, age, subscription_status, employment_status)
# Insert row into Excel sheet
path = "E:\CU WORK\#myprojects\python-excel-app\people.xlsx"
workbook = openpyxl.load_workbook(path)
sheet = workbook.active
row_values = [name, age, subscription_status, employment_status]
sheet.append(row_values)
workbook.save(path)
# Insert row into treeview
treeview.insert('', tk.END, values=row_values)
# Clear the values
name_entry.delete(0, "end")
name_entry.insert(0, "Name")
age_spinbox.delete(0, "end")
age_spinbox.insert(0, "Age")
status_combobox.set(combo_list[0])
checkbutton.state(["!selected"])
def toggle_mode():
if mode_switch.instate(["selected"]):
style.theme_use("forest-light")
else:
style.theme_use("forest-dark")
root = tk.Tk()
style = ttk.Style(root)
root.tk.call("source", "forest-light.tcl")
root.tk.call("source", "forest-dark.tcl")
style.theme_use("forest-dark")
combo_list = ["Subscribed", "Not Subscribed", "Other"]
frame = ttk.Frame(root)
frame.pack()
widgets_frame = ttk.LabelFrame(frame, text="Insert Row")
widgets_frame.grid(row=0, column=0, padx=20, pady=10)
name_entry = ttk.Entry(widgets_frame)
name_entry.insert(0, "Name")
name_entry.bind("<FocusIn>", lambda e: name_entry.delete('0', 'end'))
name_entry.grid(row=0, column=0, padx=5, pady=(0, 5), sticky="ew")
age_spinbox = ttk.Spinbox(widgets_frame, from_=18, to=100)
age_spinbox.insert(0, "Age")
age_spinbox.grid(row=1, column=0, padx=5, pady=5, sticky="ew")
status_combobox = ttk.Combobox(widgets_frame, values=combo_list)
status_combobox.current(0)
status_combobox.grid(row=2, column=0, padx=5, pady=5, sticky="ew")
a = tk.BooleanVar()
checkbutton = ttk.Checkbutton(widgets_frame, text="Employed", variable=a)
checkbutton.grid(row=3, column=0, padx=5, pady=5, sticky="nsew")
button = ttk.Button(widgets_frame, text="Insert", command=insert_row)
button.grid(row=4, column=0, padx=5, pady=5, sticky="nsew")
separator = ttk.Separator(widgets_frame)
separator.grid(row=5, column=0, padx=(20, 10), pady=10, sticky="ew")
mode_switch = ttk.Checkbutton(
widgets_frame, text="Mode", style="Switch", command=toggle_mode)
mode_switch.grid(row=6, column=0, padx=5, pady=10, sticky="nsew")
treeFrame = ttk.Frame(frame)
treeFrame.grid(row=0, column=1, pady=10)
treeScroll = ttk.Scrollbar(treeFrame)
treeScroll.pack(side="right", fill="y")
cols = ("Name", "Age", "Subscription", "Employment")
treeview = ttk.Treeview(treeFrame, show="headings",
yscrollcommand=treeScroll.set, columns=cols, height=13)
treeview.column("Name", width=100)
treeview.column("Age", width=50)
treeview.column("Subscription", width=100)
treeview.column("Employment", width=100)
treeview.pack()
treeScroll.config(command=treeview.yview)
load_data()
root.mainloop()