-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (39 loc) · 1.55 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
from bs4 import BeautifulSoup
import requests
import customtkinter
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")
app = customtkinter.CTk()
app.geometry("400x240")
url = "https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_name"
bulba = requests.get(url)
soup = BeautifulSoup(bulba.text, 'html.parser')
def invalid():
error_message = customtkinter.CTkToplevel(app)
error_message.title("Error")
error_message.geometry("200x150")
error_message.resizable(False)
label = customtkinter.CTkLabel(error_message, text="Not a Pokemon", fg_color="transparent")
label.place(relx = 0.25, rely=0.25)
def button_function():
Pokemon = entry.get()
if soup.find(title=Pokemon):
info = soup.find(title=Pokemon).parent.parent.get_text()
info = info.splitlines()
info.pop(0)
info.pop(1)
s = info[0] + "\n" + info[1] + "\n"
for i in range(len(info)-2):
s = s + info[i+2] + " "
results.configure(text=s)
else:
invalid()
button = customtkinter.CTkButton(master=app, text="Search", command=button_function)
button.place(relx = 0.1,y=150)
entry = customtkinter.CTkEntry(app, placeholder_text="Enter a Pokemon")
entry.place(relx= 0.1, y=100)
label = customtkinter.CTkLabel(app, text="Pokemon Search", fg_color="transparent")
label.place(relx = 0.1, y=50)
results = customtkinter.CTkLabel(app, text="", fg_color="transparent")
results.place(relx = .6, y=100)
app.mainloop()