-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
122 lines (100 loc) · 3.41 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
116
117
118
119
120
121
122
import tkinter as tk
from elements import Elements
length = 117
window = tk.Tk()
window.title('The Periodic Database')
label = tk.Label(text="What Element do you want to search?")
label.grid(row='1', column='9')
Elementneeded = tk.Entry(width=50)
Elementneeded.grid(row='3', column='9')
Text_box = tk.Text(height='100', width='120', wrap='word')
Text_box.grid(row='8', column='9', columnspan='1')
def Clearbox():
Text_box.delete('1.0', 'end')
Elementneeded.delete(0, 'end')
Stringvar.set('None')
Num = 0
def Next(self):
global Num
global Stringvar
try:
Num = list(Elements).index(Elementneeded.get().lower())
if Num == length:
Num = 0
Index = list(Elements.keys())[Num]
Elementneeded.delete(0, 'end')
Elementneeded.insert(0, Index)
Newindex = Elements[Index]
Text_box.delete('1.0', 'end')
Text_box.insert('1.0', Newindex)
Stringvar.set(Elementneeded.get().lower())
else:
Num = Num + 1
Index = list(Elements.keys())[Num]
Elementneeded.delete(0, 'end')
Elementneeded.insert(0, Index)
Newindex = Elements[Index]
Text_box.delete('1.0', 'end')
Text_box.insert('1.0', Newindex)
Stringvar.set(Elementneeded.get().lower())
except:
Text_box.delete('1.0', 'end')
Text_box.insert(
'1.0',
'You can not move through elements if no valid element is selected'
)
def Back(self):
global Stringvar
global Num
try:
Num = list(Elements).index(Elementneeded.get().lower())
if Num == 0:
Num = length
Index = list(Elements.keys())[Num]
Elementneeded.delete(0, 'end')
Elementneeded.insert(0, Index)
Newindex = Elements[Index]
Text_box.delete('1.0', 'end')
Text_box.insert('1.0', Newindex)
Stringvar.set(Elementneeded.get().lower())
else:
Num = Num - 1
Index = list(Elements.keys())[Num]
Elementneeded.delete(0, 'end')
Elementneeded.insert(0, Index)
Newindex = Elements[Index]
Text_box.delete('1.0', 'end')
Text_box.insert('1.0', Newindex)
Stringvar.set(Elementneeded.get().lower())
except:
Text_box.delete('1.0', 'end')
Text_box.insert(
'1.0',
'You can not move through elements if no valid element is selected'
)
lis = []
for x in range(0, length):
i = list(Elements.keys())[x]
lis.append(i)
def callback(selection):
Text_box.delete('1.0', 'end')
Text_box.insert('1.0', Elements[selection])
Elementneeded.delete(0, 'end')
Elementneeded.insert(0, selection)
def Search(self):
global Stringvar
Text_box.delete('1.0', 'end')
try:
Text_box.insert('1.0', Elements[Elementneeded.get().lower()])
Stringvar.set(Elementneeded.get().lower())
except:
Text_box.insert('1.0', 'That is not an element')
Stringvar = tk.StringVar(window, 'None')
Dropdown = tk.OptionMenu(window, Stringvar, *lis, command=callback)
Dropdown.grid(row='2', column='300', columnspan='2')
Clear = tk.Button(text="Clear", command=Clearbox)
Clear.grid(row='3', padx='500', column='300')
window.bind('<Return>', Search)
window.bind('<Right>', Next)
window.bind('<Left>', Back)
window.mainloop()