-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathjoke_bot.py
More file actions
25 lines (21 loc) · 777 Bytes
/
joke_bot.py
File metadata and controls
25 lines (21 loc) · 777 Bytes
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
import requests
import ttkbootstrap as tb
from ttkbootstrap.constants import *
def get_joke(label_text):
url = "https://icanhazdadjoke.com"
headers = {'Accept': 'application/json'}
joke_time = requests.get(url, headers=headers).json().get('joke')
label_text.set(joke_time)
print(joke_time)
def start(master) -> None:
label_text = tb.StringVar()
label = tb.Label(master, textvariable=label_text, font=("Poppins", 16), bootstyle='default')
label.pack(padx=5, pady=10)
btn = tb.Button(master, text="Get Joke!", command=lambda: get_joke(label_text))
btn.pack(padx=5, pady=10)
if __name__ == '__main__':
app = tb.Window(themename='darkly')
app.title('Joke App')
app.geometry('1280x900')
start(app)
app.mainloop()