-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.py
350 lines (240 loc) · 11.8 KB
/
interface.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
from tkinter import *
from PIL import Image, ImageTk
import requests
import pandas as pd
from dateutil.parser import ParserError
from connection import link
from tkinter import messagebox
import webbrowser
def compare():
comparewindow=Toplevel()
comparewindow.title('Compare')
def compare_currencies():
currency1 = entry_currency1.get()
currency2 = entry_currency2.get()
bool1=False
bool2=False
comparison_message=""
if not currency1 or not currency2:
messagebox.showinfo('Error', 'Please enter two different currency names for comparison.')
elif currency1 == currency2:
messagebox.showinfo('Error', 'Please enter two different currency names for comparison.')
else:
try:
for index,row in df.iterrows():
#for all information in cursor, look for the information that the user clicked on and put in in the boxes
if currency1==(row['name']):
#using the rows to recieve info
currency1name=row['name']
currency1_id=row['id']
currency1_symbol=row['symbol']
price_value = row['quote'].get('NOK', {}).get('price', 'N/A')
currency1_pricevar = f"{float(price_value):.6f} NOK"
bool1=True
for index,row in df.iterrows():
#for all information in cursor, look for the information that the user clicked on and put in in the boxes
if currency2==(row['name']):
#using the rows to recieve info
currency2name=row['name']
currency2_id=row['id']
currency2_symbol=row['symbol']
price_value2 = row['quote'].get('NOK', {}).get('price', 'N/A')
currency2_pricevar = f"{float(price_value2):.6f} NOK"
bool2=True
if bool1 and bool2:
comparison_message = (
f'Comparison between {currency1} and {currency2}:\n\n'
f'{currency1}:\n'
f'Name: {currency1name}\n'
f'ID: {currency1_id}\n'
f'Symbol: {currency1_symbol}\n'
f'Price: {currency1_pricevar}\n\n'
f'{currency2}:\n'
f'Name: {currency2name}\n'
f'ID: {currency2_id}\n'
f'Symbol: {currency2_symbol}\n'
f'Price: {currency2_pricevar}'
)
messagebox.showinfo('Currency Comparison', comparison_message)
elif bool1==False and bool2==True:
messagebox.showinfo('Error','Currency nr 1 do not exist \n Make sure your currency exists and that you have \n written it correctly')
elif bool1==True and bool2==False:
messagebox.showinfo('Error','Currency nr 2 do not exist \n Make sure your currency exists and that you have \n written it correctly')
else:
messagebox.showinfo('Error','Both of the cryptocurrencies do not exist \n Make sure your currency exists and that you have \n written it correctly')
except KeyError:
messagebox.showinfo('Error', 'Invalid currency name. Please enter valid currency names.')
entry_currency1.delete(0, 'end')
entry_currency2.delete(0, 'end')
# Create the main window
# Create and place widgets in comparewindow
label_currency1 = Label(comparewindow, text='Currency 1:')
label_currency1.grid(row=0, column=0, padx=10, pady=10, sticky='w')
entry_currency1 = Entry(comparewindow)
entry_currency1.grid(row=0, column=1, padx=10, pady=10)
label_currency2 = Label(comparewindow, text='Currency 2:')
label_currency2.grid(row=1, column=0, padx=10, pady=10, sticky='w')
entry_currency2 = Entry(comparewindow)
entry_currency2.grid(row=1, column=1, padx=10, pady=10)
btn_compare = Button(comparewindow, text='Compare', command=compare_currencies)
btn_compare.grid(row=2, column=0, columnspan=2, pady=10)
# Start the Tkinter event loop for comparewindow
comparewindow.mainloop()
def view():
viewwindow=Toplevel()
viewwindow.title('View')
def windowevent(event):
if df is not None and lst_names.curselection():
chosen=lst_names.get(lst_names.curselection())
for index,row in df.iterrows():
#for all information in cursor, look for the information that the user clicked on and put in in the boxes
if chosen==(row['name']):
#using the rows to recieve info
name.set(row['name'])
id.set(row['id'])
symbol.set(row['symbol'])
price_value = row['quote'].get('NOK', {}).get('price', 'N/A')
pricevar = f"{float(price_value):.6f} NOK"
price.set(pricevar)
def reset(event=None):
names = []
for row in df['name']:
names += [row]
list_names.set(tuple(names))
name.set('')
id.set('')
symbol.set('')
price.set('')
def searchdef(event):
check=False
if df is not None:
chosen=search.get()
for index,row in df.iterrows():
#for all information in cursor, look for the information that the user clicked on and put in in the boxes
if chosen==(row['name']):
foundlistvar=StringVar()
foundlist=[]
#using the rows to recieve info
name.set(row['name'])
id.set(row['id'])
symbol.set(row['symbol'])
price_value = row['quote'].get('NOK', {}).get('price', 'N/A')
pricevar = f"{float(price_value):.6f} NOK"
price.set(pricevar)
check=True
foundlist.append(row['name'])
lst_names=Listbox(viewwindow,width=25,height=10,listvariable=foundlistvar)
list_names.set(tuple(foundlist))
if check==False:
message=f"The cryptocurrency {chosen} doesnt exist!\n Remember to spell correctly and beware of \n capital and special letters!!"
messagebox.showinfo('Not Found',message)
names=[]
for row in df['name']:
names+=[row]
list_names=StringVar()
lst_names=Listbox(viewwindow,width=25,height=10,listvariable=list_names)
lst_names.grid(row=1,column=1,rowspan=2,pady=5,sticky=W)
list_names.set(tuple(names))
scrollbar = Scrollbar(viewwindow, orient="vertical", command=lst_names.yview)
scrollbar.grid(row=1, column=2, rowspan=2, sticky="ns")
# Configure the Listbox to use the scrollbar
lst_names.configure(yscrollcommand=scrollbar.set)
#stringvars
name=StringVar()
ent_pc=Entry(viewwindow,width=25,textvariable=name,state='readonly')
ent_pc.grid(row=3,column=1,sticky=W)
id=StringVar()
ent_pc=Entry(viewwindow,width=25,textvariable=id,state='readonly')
ent_pc.grid(row=4,column=1,sticky=W)
price=StringVar()
ent_location=Entry(viewwindow,width=25,textvariable=price,state='readonly')
ent_location.grid(row=6,column=1,sticky=W)
symbol=StringVar()
ent_dato=Entry(viewwindow,width=20,textvariable=symbol,state='readonly')
ent_dato.grid(row=5,column=1,sticky=W)
#labels
lbl_name=Label(viewwindow,text='Name: ')
lbl_name.grid(row=3,column=0,sticky=W)
#labels
lbl_id=Label(viewwindow,text='ID: ')
lbl_id.grid(row=4,column=0,sticky=W)
lbl_symbol=Label(viewwindow,text='Symbol: ')
lbl_symbol.grid(row=5,column=0,sticky=W)
lbl_price=Label(viewwindow,text='Price: ')
lbl_price.grid(row=6,column=0,sticky=W)
lbl_location=Label(viewwindow,text='Currencies: ')
lbl_location.grid(row=1,column=0,sticky=W)
lbl_location=Label(viewwindow,text='Search: ')
lbl_location.grid(row=8,column=0,sticky=W)
#important as the event parameter
lst_names.bind('<<ListboxSelect>>',windowevent)
viewwindow.bind('<Return>', searchdef)
search=StringVar()
searchbar=Entry(viewwindow,width=25,textvariable=search)
searchbar.grid(row=8,column=1,sticky=E)
enter=Button(viewwindow, text ="Search",bg='green', command = searchdef)
restart=Button (viewwindow, text ="Reset",bg='orange', command = reset)
enter.grid(row=8,column=5,sticky=E,padx=5,pady=25)
restart.grid(row=8,column=6,sticky=E,padx=5,pady=25)
btn_avslut2=Button(viewwindow,text='Quit',bg='red',command=viewwindow.destroy)
btn_avslut2.grid(row=8,column=7,padx=5,pady=25,sticky=E)
def about():
aboutuswindow=Toplevel()
aboutuswindow.title('About')
title_label = Label(aboutuswindow, text="Welcome to my application!", font=("Helvetica", 16, "bold"))
title_label.pack(pady=10)
about_us_text = """
This application is designed to showcase and compare cryptocurrencies.
It was created as a project for me to learn more about APIs. In this
application, i am working with the API of CoinMarketCap.
I have also added some functions, in order for me to learn more about
the world of programming.
Version: 1.0
Released: N/A
Thank you for using my application!
"""
label = Label(aboutuswindow, text=about_us_text, font=("Helvetica",13), padx=10, pady=10)
label.pack()
def AI():
comparewindow=Toplevel()
comparewindow.title('ChatBot')
about_us_text = """
This function will be included in the next update!
"""
label = Label(comparewindow, text=about_us_text,font=("Helvetica", 16, "bold"), padx=10, pady=10)
label.pack()
def visit():
webbrowser.open('https://github.com/lak1811')
root = Tk()
root.title("Menu")
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Compare", command=compare)
filemenu.add_command(label="Show", command=view)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="View Currencies", menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About...", command=about)
helpmenu.add_command(label="Chat with us!", command=AI)
menubar.add_cascade(label="Help", menu=helpmenu)
visitmenu = Menu(menubar, tearoff=0)
visitmenu.add_command(label="Look at my other projects!", command=visit)
menubar.add_cascade(label="Visit", menu=visitmenu)
url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
# Define parameters and headers
parameters = {
'start': '1',
'limit': '5000',
'convert': 'NOK'
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': '282390ec-34c2-4ffd-8010-12d856686b67',
}
df=link(url,parameters,headers)
img = ImageTk.PhotoImage(Image.open("logo.jpeg"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.config(menu=menubar,background="#87CEEB")
root.mainloop()