Pokedex in Python ...
If you are a programmer who loves Pokemon ...
... then this project is for you
pypokedex => PyPokedex is a minimal pokedex library for Python that uses PokeAPI internally to get Pokemon data. More information on : pypokedex
urllib3 => urllib3 is a powerful, user-friendly HTTP client for Python. Much of the Python ecosystem already uses urllib3 and you should too. More information on : urllib3
Pillow => Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. As of 2019, Pillow development is supported by Tidelift. More information on : Pillow
io => The io
module provides Python’s main facilities for dealing with various types of I/O. There are three main types of I/O: text I/O, binary I/O and raw I/O. These are generic categories, and various backing stores can be used for each of them. A concrete object belonging to any of these categories is called a file object. More information on : docs.python.org/io
tkinter => Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way to create GUI applications. Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit. Creating a GUI application using Tkinter is an easy task. More information on : Tkinter
import pypokedex # pip install pypokedex
import urllib3 # pip install urllib3
import PIL.Image,PIL.ImageTk # pip install Pillow
from io import BytesIO # inbuilt
import tkinter as tk # inbuilt
root=tk.Tk() # initializing tkinter
root.title('POKEDEX') # tkinter configurations ..
root.geometry('600x550')
root.config(padx=10,pady=10)
title_lbl=tk.Label(root,text='POKEDEX') # tkinter label
title_lbl.config(font=('Arial',32))
title_lbl.pack(padx=10,pady=10)
pokemon_img=tk.Label(root) # tkinter image
pokemon_img.pack(padx=10,pady=10)
poke_info=tk.Label(root) # info on pokemon
poke_info.config(font=('Arial',20))
poke_info.pack(padx=10,pady=10)
poke_types=tk.Label(root) # type of pokemon
poke_types.config(font=('Arial',20))
poke_types.pack(padx=10,pady=10)
poke_base=tk.Label(root) # base experience
poke_base.config(font=('Arial',20))
poke_base.pack(padx=10,pady=10)
poke_id_name=tk.Label(root,text='Name or ID') # name and id
poke_id_name.config(font=('Arial',20))
poke_id_name.pack(padx=10,pady=10)
def pokemon_load(): # function to get information from pokemon website
pokemon=pypokedex.get(name=text_id_name.get(1.0,"end-1c"))
http=urllib3.PoolManager()
response=http.request('GET',pokemon.sprites.front.get('default'))
image=PIL.Image.open(BytesIO(response.data))
img=PIL.ImageTk.PhotoImage(image)
pokemon_img.config(image=img)
pokemon_img.image=img
poke_info.config(text=f'{pokemon.dex} - {pokemon.name}' )
poke_types.config(text=" - ".join([t for t in pokemon.types]))
poke_base.config(text=f' base-experience - {pokemon.base_experience}')
text_id_name=tk.Text(root,height=1) # Text Widget - where you type
text_id_name.config(font=('Arial',20))
text_id_name.pack(padx=10,pady=10)
btn_load=tk.Button(root,text='Load',command=pokemon_load) # Button Widget
btn_load.config(font=('Arial',20))
btn_load.pack(padx=10,pady=10)
root.mainloop() # loop
And the output ...
Comments
Post a Comment