-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathpython_tkinter_gui.py
More file actions
57 lines (40 loc) · 1.17 KB
/
python_tkinter_gui.py
File metadata and controls
57 lines (40 loc) · 1.17 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
#www.atozknowledge.com
#youtube.com/atozknowledge.com
from openpyxl import *
from tkinter import *
wb = load_workbook(r'data.xlsx')
sheet = wb.active
def excel():
sheet.column_dimensions['A'].width = 30
sheet.cell(row=1, column=1).value = "Name"
def clear():
name_field.delete(0, END)
def insert():
if (name_field.get() == ""):
print("empty input")
else:
current_row = sheet.max_row
current_column = sheet.max_column
sheet.cell(row=current_row + 1, column=1).value = name_field.get()
wb.save(r'data.xlsx')
clear()
# Driver code
if __name__ == "__main__":
# create a GUI window
root = Tk()
root.title("registration form")
excel()
# create a Name label
name = Label(root, text="Name")
name.grid(row=1, column=0)
# create a text entry box
# for typing the information
name_field = Entry(root)
name_field.grid(row=1, column=1, ipadx="100")
# call excel function
excel()
# create a Submit Button and place into the root window
submit = Button(root, text="Submit", command=insert)
submit.grid(row=8, column=1)
# start the GUI
root.mainloop()