-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
104 lines (91 loc) · 4.99 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# . .
# :-:--=:-:::. :=-**##*=:
# :=----------. .-%@@@@@@@@@%:
# :-------------: :@@@@@@@@@@@@%.
# :-=-----------==: +@@@@@@@@@@@@@#
# .------------=------. =@@@@@@@@@@@@@#
# :=-=-------===-=-- .+%@@@@@@@@@@@#=
# --=--------==-=-. -*%@@@@@@@@@*-.
# ::----===+- .#%@@@@*.
# -+++=: . :+##+
# -+=====. .=%@@%%%#=
# :-----------:. :+#%%%@@@@@%@%+-
# ----------------- -%%%%%@@@%@@%%@%%*
# .-==----------==--: #%%%@%@@@@@@@@@@%%.
# :-=+----------*=--- =%%%@@%%@@@%%@@@%%%=
# ---=----------*----: .#%%%@@%%@@@%@%@@%%%%
# :-===----------+=---= -#%%%@@%%@%@%@%@@%%%%=
# --=----------=#==+. ==+%@@%%@@@%@%@@*++.
# --=-----------*=--- :===#@@%%@@@%@%%%--=
# -==-----------++--= ---:#@%@@@%%%@@@%--=
# -=------------=:--=. =-- %@%%%%%%@%%%@=-=
# .-+-------------.:---.--: %%%%%%%%@%%@@+==
# :-++*++++++*+***. --=+-- *###########**-=
# --*+++++++++*+++: :--*-: :------=------*-=
# =-*++++++++*+***- .--*-. :-------------+-=
# .--*+++=+*++*+***+ :==*=: -------=------===:
# :=+++++==+++*++**+ -*++=. -------+-------+=:
# -++++=+==**+++*** :-: -------+-------+.
# -+++=++=****+**# -------+=------=
# .++==*=---=*+**+ =------+*------=
# ----= :---= ====-.::+====
# :**#==---=: ----= .. .:::=--=+*%#*--=+***. .--:..
# .=+**#=--== :=--=%@*:.-=+%%*--=: ::+=--+***+=#@%*-=-::.
# :+=--=. :::=--=:.-*#%*--=*---+-+**=--=--=+**+*=**%@%=
# =--= .#%%=--=. +*#%#= +---#%++#=---.+%@%+ .+++*+-
# ==== .:+===: -==+= :===*+: -==== .--:. ..
# =--= ----: .---- :=---
# ---- :---: .=--- .=---
# ---- :---: .=--- =---
# ---: :---: .=--- +---
# +##%. =*##- -%%#: %%%#
# :@@@@- #@@@+ %@@@* :@@@%:
# .====. -++=: =+==- --==.
# @milosnowcat
import requests
import tkinter as ttk
import ttkbootstrap as ttk
from fontTools.ttLib import TTFont
URL = "https://api.quotable.io/random?tags=technology"
def select_font(type):
"""
The function `select_font` takes a font type as input and returns the corresponding font file.
:param type: The "type" parameter is a string that represents the specific font type or style that
you want to select. It is used to construct the font path by appending it to the base font file name
"Poppins-" and the file extension ".ttf"
:return: the variable `my_font`, which is an instance of the `TTFont` class.
"""
font_path = f"assets/fonts/Poppins-{type}.ttf"
my_font = TTFont(font_path)
return my_font
def get_quote():
"""
The function `get_quote` sends a GET request to a specified URL, retrieves JSON data, extracts a
quote and its author from the data, and returns them as a tuple.
:return: a quote and its author.
"""
response = requests.get(URL)
data = response.json()
quote = data["content"]
author = data["author"]
return quote, author
def update_quote():
"""
The function `update_quote` updates the text of a quote label and author label with a new quote and
author obtained from the `get_quote` function.
"""
quote, author = get_quote()
quote_label.config(text=quote)
author_label.config(text=f"~{author}")
# This code is creating a graphical user interface (GUI) using the tkinter library in Python.
root = ttk.Window(themename="vapor")
root.title("Quote.py")
root.geometry("700x250")
frm = ttk.Frame(root)
frm.pack(padx=30, pady=40)
quote_label = ttk.Label(frm, text="", font=(select_font("Medium"), 16), wraplength=650)
quote_label.pack()
author_label = ttk.Label(frm, text="", font=(select_font("Regular"), 12))
author_label.pack(pady=10)
ttk.Button(frm, text="Get Quote", command=update_quote).pack(pady=20)
root.mainloop()