Skip to content

Commit f423974

Browse files
committed
added quote generator
1 parent 051c379 commit f423974

6 files changed

+81
-0
lines changed
Loading
Loading
Loading

Quote Generator/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
**QUOTE GENERATOR**
2+
3+
**GOAL**
4+
The Goal of this app to Show Random Quote.
5+
6+
**DESCRIPTION**
7+
This is a Quote Generator in python, made using Tkinter.
8+
9+
### LIBRARIES NEEDED
10+
11+
1. Tkinter: Provides great utility for making useful UIs
12+
2. Requests package: This is used to fetch random quote from "http://api.quotable.io/random".
13+
3. Threads: used to generate new quote and store it in quotes list in background.
14+
15+
**WHAT I HAD DONE**
16+
1) Import Tkinter, and defined the screen using it.
17+
2) Import Request package and use it to generate a random quote, and add it to quotes list.
18+
3) Created a quote label to print quote on screen, and a button to generate a random quote every time it is clicked.
19+
4) Applied Color Scheme to make it look more appealing.
20+
21+
### DEMONSTRATION
22+
https://drive.google.com/drive/folders/1pLjCBYRUCPAfVfG6atZtpfVq0rCmUz3E?usp=share_link
23+
24+
### Sarthak Joleya ###

Quote Generator/main.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import tkinter as tk
2+
import requests
3+
from threading import Thread
4+
5+
api = "http://api.quotable.io/random"
6+
quotes = []
7+
quote_number = 0
8+
MAX_QUOTES = 5
9+
10+
#Configuring Screen
11+
screen = tk.Tk()
12+
screen.geometry("900x268")
13+
screen.title("Random Quote Generator")
14+
screen.grid_columnconfigure(0, weight=1)
15+
screen.resizable (False, False)
16+
screen.configure(bg = '#5271E8')
17+
18+
19+
#Functions
20+
def load_quotes():
21+
global quotes
22+
print('Loading Quotes. Please Wait a Moment')
23+
for x in range(MAX_QUOTES):
24+
random_quote = requests.get(api).json()
25+
content = random_quote['content']
26+
author = random_quote['author']
27+
quote = '"' + content + '"' + "\n\n" + "By " + author
28+
# print(quote)
29+
quotes.append(quote)
30+
31+
load_quotes()
32+
33+
def get_random_quote():
34+
global quote_label
35+
global quotes
36+
global quote_number
37+
38+
quote_label.configure(text=quotes[quote_number])
39+
quote_number = quote_number + 1
40+
# print(quote_number)
41+
if quotes[quote_number] == quotes[-3]:
42+
thread = Thread(target=load_quotes)
43+
thread.start()
44+
45+
46+
# UI
47+
quote_label = tk.Label(screen, text="Click to generate new Quote", bg='#C9F4F9',height=6, pady=10, wraplength=800, font=("Times New Roman", 15, 'italic'))
48+
quote_label.grid(row=0,column=0, stick="WE", padx=20, pady=10)
49+
50+
button = tk.Button(text="Generate", command=get_random_quote, bg='#ffffff', font=("Times New Roman", 14))
51+
button.grid(row=1,column=0, stick="WE", padx=20, pady=10)
52+
53+
#Main Loop
54+
screen.mainloop()

Quote Generator/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The required library is:
2+
3+
requests(command: pip install requests)

0 commit comments

Comments
 (0)