-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDGUI.py
100 lines (77 loc) · 2.44 KB
/
TDGUI.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
# import pygame
# from pygame.locals import *
# pygame.init()
# white = (255, 255, 255)
# red = (255, 0, 0)
# green = (0, 255, 0)
# blue = (0, 0, 255)
# (width, height) = (300, 200)
# screen = pygame.display.set_mode((width, height))
# pygame.display.set_caption('Tutorial 1')
# pygame.display.flip()
# RUNNING = True
# while RUNNING:
# for event in pygame.event.get():
# print(event)
# if event.type == pygame.QUIT:
# pygame.quit()
# quit()
# screen.fill(white)
# large_text = pygame.font.Font('freesansbold.ttf',115)
# pygame.draw.rect(screen, green,(150,450,100,50))
# pygame.draw.rect(screen, red,(550,450,100,50))
# pygame.display.updates
# import tkinter as tk
# def write_slogan():
# print("Tkinter is easy to use!")
# root = tk.Tk()
# frame = tk.Frame(root)
# frame.pack()
# button = tk.Button(frame,
# text="QUIT",
# fg="red",
# command=quit)
# button.pack(side=tk.LEFT)
# slogan = tk.Button(frame,
# text="Hello",
# command=write_slogan)
# slogan.pack(side=tk.LEFT)
# T = tk.Text(root, height=2, width=30)
# T.pack()
# T.insert(tk.END, "Just a text Widget\nin two lines\n")
# tk.mainloop()
# root.mainloop()
import tkinter as tk
fields = 'Side', 'Ticker', 'Level', 'PT'
def fetch(entries):
for entry in entries:
field = entry[0]
text = entry[1].get()
print('%s: "%s"' % (field, text))
def makeform(root, fields):
entries = []
for field in fields:
row = tk.Frame(root)
lab = tk.Label(row, width=5, text=field, anchor='w')
ent = tk.Entry(row)
row.pack(side=tk.LEFT, fill=tk.X, padx=1, pady=5)
lab.pack(side=tk.LEFT)
ent.pack(side=tk.RIGHT, expand=tk.YES, fill=tk.X)
entries.append((field, ent))
return entries
def add_watch(entries):
for entry in entries:
field = entry[0]
text = entry[1]
print('%s: "%s"' % (field, text.get()))
text.delete(0, tk.END)
if __name__ == '__main__':
root = tk.Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: fetch(e)))
b1 = tk.Button(root, text='Add',
command=(lambda e=ents: add_watch(e)))
b1.pack(side=tk.BOTTOM, padx=5, pady=5)
b2 = tk.Button(root, text='Quit', command=root.quit)
b2.pack(side=tk.BOTTOM, padx=5, pady=5)
root.mainloop()