forked from jigar-sable/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokedex_gui.py
60 lines (48 loc) · 1.8 KB
/
pokedex_gui.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
import pypokedex
import PIL.Image,PIL.ImageTk
import tkinter as tk
import urllib3
from io import BytesIO
#building the gui
window=tk.Tk()
window.geometry("600x500")
window.title("Pokedex- A big pokemon fan")
window.config(padx=10, pady=10)
pokemon_image=tk.Label(window)
pokemon_image.pack(padx=10, pady=10)
#setting the title
title_label=tk.Label(window,text="Pokedex")
title_label.config(font=("Arial",28))
title_label.pack(padx=10,pady =10)
pokemon_information=tk.Label(window)
pokemon_information.config(font=("Arial",20))
pokemon_information.pack(padx=10,pady =10)
pokemon_types=tk.Label(window)
pokemon_types.config(font=("Arial",20))
pokemon_types.pack(padx=10,pady =10)
#function to load image and information of pokemon
def load_pokemon():
#matching id and name
pokemon=pypokedex.get(name=text_id_name.get(1.0,"end-1c"))
http = urllib3.PoolManager()
#getting the image
response= http.request('GET',pokemon.sprites.front.get('default'))
image=PIL.Image.open(BytesIO(response.data))
#saving the image on GUI
img=PIL.ImageTk.PhotoImage(image)
pokemon_image.config(image=img)
pokemon_image.image=img
#saving the type /characteristic of character
pokemon_information.config(text=f"{ pokemon.dex}- {pokemon.name}".title())
pokemon_types.config(text=" - ".join([t for t in pokemon.types]).title())
#applying the proper location
label_id_name=tk.Label(window,text="ID Or Name")
label_id_name.config(font=("Arial",20))
label_id_name.pack(padx=10,pady =10)
text_id_name=tk.Text(window,height=1)
text_id_name.config(font=("Arial",20))
text_id_name.pack(padx=10,pady =10)
btn_load=tk.Button(window, text="Load Pokemon",command=load_pokemon)
btn_load.config(font=("Arial",20))
btn_load.pack(padx=10,pady =10)
window.mainloop()