requests를 통해 API에 접속해서 간단한 데이터를 받아와 tkinter을 사용한 프로젝트이다.

칸예웨스트 얼굴 버튼을 클릭 시 명언이 바뀐다.

https://blog.kakaocdn.net/dn/CKoGS/btrEXkL9QiK/Wy9BYRaLi8qkkx9iwRzYf1/img.png

from tkinter import *
import requests

API_ENDPOINT = "<https://api.kanye.rest/>"

def get_quote():
    reseponse = requests.get(url=API_ENDPOINT)
    data = reseponse.json()
    canvas.itemconfig(quote_text,text=data["quote"])

window = Tk()
window.title("Kanye Says...")
window.config(padx=50, pady=50)

canvas = Canvas(width=300, height=414)
background_img = PhotoImage(file="background.png")
canvas.create_image(150, 207, image=background_img)
quote_text = canvas.create_text(150, 207, text="Kanye Quote Goes HERE", width=250, font=("Arial", 30, "bold"), fill="white")
canvas.grid(row=0, column=0)

kanye_img = PhotoImage(file="kanye.png")
kanye_button = Button(image=kanye_img, highlightthickness=0, command=get_quote)
kanye_button.grid(row=1, column=0)

window.mainloop()