Apr-02-2024, 07:44 PM
Gets random quote from internet
import requests import json import tkinter as tk root = tk.Tk() root.title('Random quote of the day') def get_quote(): frame = tk.Frame(root) frame.grid(column=0, row=1, sticky='news', padx=1) url = 'https://api.quotable.io/random' quote = json.loads(requests.get(url).text) edits = ['dateAdded', 'dateModified'] unwanted = ['length','_id', 'tags', 'authorSlug'] index = 0 for prefix, data in quote.items(): prefix = 'quote' if prefix == 'content' else prefix if prefix in edits: prefix = f'{prefix[0:4].title()} {prefix[4:]}' if prefix not in unwanted: label = tk.Label(frame, text=prefix.title(), anchor='w') label['highlightbackground'] = 'black' label['highlightcolor'] = 'black' label['highlightthickness'] = 1 label['font'] = None, 11, 'bold' label.grid(column=0, row=index, sticky='new', padx=(5,1), pady=5) label = tk.Label(frame, text=data, anchor='w', justify='left', padx=5, pady=5) label['highlightbackground'] = 'black' label['highlightcolor'] = 'black' label['highlightthickness'] = 1 label['wraplength'] = 400 label.grid(column=1, row=index, sticky='new', padx=(1,5), pady=5) index += 1 title = tk.Label(root, text='Quote of the day', font=(None, 25, 'bold'), pady=8, padx=8) title['bg'] = 'slategray' title['fg'] = 'white' title.grid(column=0, row=0, sticky='new', padx=5, pady=5) get_quote() button = tk.Button(root, text='Get Random Quote', command=get_quote) button.grid(column=0, row=2, sticky='news', padx=5, pady=5) root.mainloop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts