forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvisor.py
More file actions
executable file
·38 lines (29 loc) · 914 Bytes
/
advisor.py
File metadata and controls
executable file
·38 lines (29 loc) · 914 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
33
34
35
36
37
38
# Importing libraries
import requests
import tkinter as tk
from tkinter import messagebox
# Fetching advice from the advice api
def advice():
try:
res = requests.get("https://api.adviceslip.com/advice").json()
advice_text.set(res["slip"]["advice"])
except requests.exceptions.RequestException:
messagebox.showerror(
"Error", "Failed to fetch advice. Please check your internet connection."
)
# Create the main window
root = tk.Tk()
root.title("Random Advisor Application")
# Create and configure widgets
advice_text = tk.StringVar()
advice_label = tk.Label(
root, textvariable=advice_text, wraplength=400, font=("Arial", 14)
)
get_advice_button = tk.Button(root, text="Get Advice", command=advice)
# Pack widgets
advice_label.pack(pady=20)
get_advice_button.pack(pady=10)
# Initial advice fetching
advice()
# Run the main event loop
root.mainloop()