-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote_generator.py
37 lines (23 loc) · 1.03 KB
/
quote_generator.py
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
from tkinter import *
import requests
import random
class QuoteGenerator:
def __init__(self,master):
self.master=master
self.master.title("Quote Generator")
self.master.geometry("1000x250")
self.quote_label=Label(self.master,wraplength=800,font=("Courier New",14))
self.quote_label.configure(text="")
self.quote_label.pack(ipadx=20,ipady=20,padx=20,pady=20)
self.generate_quote_button=Button(self.master,text='Generate!',command=self.generate,width=30,font=("Courier New",14),bg="#0c20f7",activebackground="#2839f7",fg="white",activeforeground="white")
self.generate_quote_button.pack()
self.master.mainloop()
def generate(self):
self.quote_label.configure(text="")
quote_json=requests.get("http://api.quotable.io/random").json()
quote="{}\n\nBy: {}".format(quote_json['content'],quote_json['author'])
print(quote)
self.quote_label.configure(text=quote)
if __name__=="__main__":
root=Tk()
app=QuoteGenerator(root)