-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathventana.py
93 lines (59 loc) · 2.46 KB
/
ventana.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
from tkinter import *
from PIL import Image,ImageTk
import requests
from io import BytesIO
import pokebase as pb
class root:
def __init__(self):
self.title="POKEDEX"
self.size="600x700"
self.resiable=False
self.icon='icono.ico'
def search(self):
self.details.delete('1.0',END)
#search a pokemon
self.pokemon=pb.pokemon(self.poke_inp.get())
try:
#request
self.response=requests.get(self.pokemon.sprites.front_default)
self.image=ImageTk.PhotoImage(Image.open(BytesIO(self.response.content)))
self.pokemon_image.config(image=self.image)
self.pokemon_image.image=self.image
self.abilities = ''
self.types= ''
for self.ability in self.pokemon.abilities:
self.abilities += self.ability.ability.name + ', '
for poketype in self.pokemon.types:
self.types += poketype.type.name + ', '
self.data=f"""{self.poke_inp.get().capitalize()}
\nHeight:{self.pokemon.height}
\nWeight:{self.pokemon.weight}
\nAbilities:{self.abilities}
\nType:{self.types}
"""
self.details.insert(END,self.data)
except AttributeError:
self.details.insert(END,"Not a valid pokemon try again")
self.pokemon_image.config(image='')
def cargar(self):
self.ventana=Tk()
self.ventana.title(self.title)
self.ventana.iconbitmap(self.icon)
self.ventana.geometry(self.size)
self.ventana.resizable(0,0)
self.logo="logo.png"
self.img=ImageTk.PhotoImage(Image.open(self.logo))
self.banner=Label(self.ventana,image=self.img)
self.banner.image=self.img
self.banner.pack()
self.label2=Label(self.ventana,text="Enter the name of pokemon", fg="red",pady=20,font=("Ubuntu",18))
self.label2.pack()
self.poke_inp=Entry(self.ventana,font=('Ubuntu',18))
self.poke_inp.pack(pady=20)
self.but=Button(self.ventana,bd='4',text="Submit",fg="red",bg="yellow",command=self.search)
self.but.pack()
self.pokemon_image=Label(self.ventana)
self.pokemon_image.pack(pady=30)
self.details=Text(self.ventana,font=("Ubuntu",12),bg='light yellow')
self.details.pack()
self.ventana.mainloop()