Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit a9050e7

Browse files
committed
simple gui advisor
1 parent 3ad3576 commit a9050e7

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

projects/Advisor/advisor.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Importing libraries
2+
import requests
3+
import tkinter as tk
4+
from tkinter import messagebox
5+
6+
# Fetching advice from the advice api
7+
8+
9+
def advice():
10+
try:
11+
res = requests.get("https://api.adviceslip.com/advice").json()
12+
advice_text.set(res["slip"]["advice"])
13+
except requests.exceptions.RequestException:
14+
messagebox.showerror(
15+
"Error", "Failed to fetch advice. Please check your internet connection.")
16+
17+
18+
# Create the main window
19+
root = tk.Tk()
20+
root.title("Random Advisor Application")
21+
22+
# Create and configure widgets
23+
advice_text = tk.StringVar()
24+
advice_label = tk.Label(root, textvariable=advice_text,
25+
wraplength=400, font=("Arial", 14))
26+
get_advice_button = tk.Button(root, text="Get Advice", command=advice)
27+
28+
# Pack widgets
29+
advice_label.pack(pady=20)
30+
get_advice_button.pack(pady=10)
31+
32+
# Initial advice fetching
33+
advice()
34+
35+
# Run the main event loop
36+
root.mainloop()

0 commit comments

Comments
 (0)