카테고리 없음

[34-2 파이썬] tkinter로 O, X 버튼 있는 GUI 만들기

Olivia-BlackCherry 2022. 9. 26. 17:11

#tkinter 전부 import
from tkinter import *
#배경색깔 지정
THEME_COLOR = "#375362"

#윈도우 생성, 제목, 여백, 배경색깔
window= Tk()
window.title("Quiz")
window.config(padx=20, pady=20, bg= THEME_COLOR)

#라벨생성, 배경, 글자색깔, 여백, 배치
score_label = Label(text="score:0", bg=THEME_COLOR, fg= "white", padx=10, pady=10)
score_label.grid(row=0, column=1)

#캔버스 생성, 너비 높이, 배경, 텍스트 덮어쓰기, 폰트체 조절, 배치, 여백
canvas = Canvas(width=300, height=250, bg="white")
canvas.create_text(150, 125, text="this is the question", font=("Arial", 20, "italic"))
canvas.grid(row=1, column=0, columnspan=2, padx=20, pady=20)

#이미지 다운로드, 버튼 생성
true_image = PhotoImage(file="images/true.png")
true_button = Button(image=true_image)
true_button.grid(row=2, column=0)

false_image = PhotoImage(file = "images/false.png")
false_button = Button(image=false_image)
false_button.grid(row=2, column=1)

#while 구문처럼 무한재생하는 느낌!
window.mainloop()