-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinter_example.py
More file actions
32 lines (25 loc) · 834 Bytes
/
tkinter_example.py
File metadata and controls
32 lines (25 loc) · 834 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
26
27
28
29
30
31
32
import tkinter as tk
import requests
# Create a function to handle the button click event
def button_click():
response = requests.get('https://icanhazdadjoke.com/', headers={'Accept': 'application/json'})
if response.status_code == 200:
# Extract the joke from the response
joke_data = response.json()
joke = joke_data['joke']
label.config(text=joke)
# Create the main window
root = tk.Tk()
root.title("Dad Joke Generator")
root.geometry("500x500")
# Create a label widget
label = tk.Label(root, text="Joke Generator!")
hello_label = tk.Label(root, text=joke)
# Create a button widget
button = tk.Button(root, text="New Joke", command=button_click)
# Pack the label and button widgets into the window
label.pack()
hello_label.pack()
button.pack()
# Start the main event loop
root.mainloop()