forked from markmbadham/pythoncourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form_Class.py
34 lines (27 loc) · 870 Bytes
/
Form_Class.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
import tkinter as tk
class Form(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.rows = 0
self.entries = {}
self.setup()
def add_row(self, title):
label = tk.Label(text=title)
label.grid(row=self.rows, column=0)
entry = tk.Entry()
entry.grid(row=self.rows, column=1)
self.entries[title] = entry
self.rows+=1
def button_action(self):
for key in self.entries:
print(key, self.entries[key].get())
def setup_rows(self, *titles):
for title in titles:
self.add_row(title)
def setup(self):
self.setup_rows('Name','Surname','Age')
button = tk.Button(text='Print', command=self.button_action)
button.grid(row=self.rows+1,column=0)
self.mainloop()
if __name__ == '__main__':
win = Form()