Skip to content

Commit b50a872

Browse files
authored
Create joke_bot.py
Added a joke bot which uses the icanhazdadjoke and ttkbootstrap
1 parent 7e00fe0 commit b50a872

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

joke_bot.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests
2+
import ttkbootstrap as tb
3+
from ttkbootstrap.constants import *
4+
5+
def get_joke(label_text):
6+
url = "https://icanhazdadjoke.com"
7+
headers = {'Accept': 'application/json'}
8+
joke_time = requests.get(url, headers=headers).json().get('joke')
9+
label_text.set(joke_time)
10+
print(joke_time)
11+
12+
def start(master) -> None:
13+
label_text = tb.StringVar()
14+
label = tb.Label(master, textvariable=label_text, font=("Poppins", 16), bootstyle='default')
15+
label.pack(padx=5, pady=10)
16+
btn = tb.Button(master, text="Get Joke!", command=lambda: get_joke(label_text))
17+
btn.pack(padx=5, pady=10)
18+
19+
if __name__ == '__main__':
20+
app = tb.Window(themename='darkly')
21+
app.title('Joke App')
22+
app.geometry('1280x900')
23+
start(app)
24+
app.mainloop()
25+

0 commit comments

Comments
 (0)