Skip to content

Commit 624832c

Browse files
Created GUI 😎
1 parent 1887d9c commit 624832c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

Advisor_App/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Run the command in terminal to install package
1313
```
1414
$ pip install requests
1515
```
16+
```
17+
$ pip install tkinter
18+
```
1619
Run the program using command
1720

1821
```

Advisor_App/advice.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
# Importing files
1+
# Importing libraries
22
import requests
3+
import tkinter as tk
4+
from tkinter import messagebox
35

4-
# Function taking api link and fetch random advice quotes
6+
# Fetching advice from the advice api
57
def advice():
6-
res = requests.get("https://api.adviceslip.com/advice").json()
7-
print("\n")
8-
print(res["slip"]["advice"])
9-
print("\n")
8+
try:
9+
res = requests.get("https://api.adviceslip.com/advice").json()
10+
advice_text.set(res["slip"]["advice"])
11+
except requests.exceptions.RequestException:
12+
messagebox.showerror("Error", "Failed to fetch advice. Please check your internet connection.")
1013

14+
# Create the main window
15+
root = tk.Tk()
16+
root.title("Random Advisor Application")
17+
18+
# Create and configure widgets
19+
advice_text = tk.StringVar()
20+
advice_label = tk.Label(root, textvariable=advice_text, wraplength=400, font=("Arial", 14))
21+
get_advice_button = tk.Button(root, text="Get Advice", command=advice)
22+
23+
# Pack widgets
24+
advice_label.pack(pady=20)
25+
get_advice_button.pack(pady=10)
26+
27+
# Initial advice fetching
1128
advice()
29+
30+
# Run the main event loop
31+
root.mainloop()

0 commit comments

Comments
 (0)