Skip to content

Instantly share code, notes, and snippets.

@WhiteHyun
Created December 12, 2021 10:17
Show Gist options
  • Save WhiteHyun/e9fddfc1a1b071edf89a17ed1c43b8ae to your computer and use it in GitHub Desktop.
Save WhiteHyun/e9fddfc1a1b071edf89a17ed1c43b8ae to your computer and use it in GitHub Desktop.
tkinter 외주
from tkinter import *
# 창 생성
win = Tk() # 창을 변수로 만들어주어야 한다
win.geometry("700x500") # 창 크기
win.resizable(height=None, width=None) # 창 크기 조절 가능?
win.title("todolist") # 창 제목
# win.option_add("*Font","맑은고딕 10") # 글씨체, 크기
# 화면분할용 프레임
todo_frame = Frame(win)
plant_frame = Frame(win)
# 오늘의 할일 라벨
lb = Label(todo_frame, bg="white", fg="black")
lb.config(text="오늘의 할일")
lb.pack(side="top", pady=(40, 10))
todo_frame.pack(side="left", fill="both", expand=True)
plant_frame.pack(side="right", fill="both", expand=True)
todo_frame.configure(bg="white") # 창 색상 설정
plant_frame.configure(bg="white") # 창 색상 설정
# 체크버튼
cv1 = BooleanVar() # 체크가 되어있는지 아닌지 구분, 안하면 False, 하면 True
cv2 = BooleanVar()
cv3 = BooleanVar()
cv4 = BooleanVar()
cv5 = BooleanVar()
# 체크되어있는지 아닌지에 따라 cv의 상태가 바뀜
cb1 = Checkbutton(todo_frame, text="1번", variable=cv1, bg="white", fg="black")
cb2 = Checkbutton(todo_frame, text="2번", variable=cv2, bg="white", fg="black")
cb3 = Checkbutton(todo_frame, text="3번", variable=cv3, bg="white", fg="black")
cb4 = Checkbutton(todo_frame, text="4번", variable=cv4, bg="white", fg="black")
cb5 = Checkbutton(todo_frame, text="5번", variable=cv5, bg="white", fg="black")
cb1.pack(anchor="w", padx=10, pady=10)
cb2.pack(anchor="w", padx=10, pady=10)
cb3.pack(anchor="w", padx=10, pady=10)
cb4.pack(anchor="w", padx=10, pady=10)
cb5.pack(anchor="w", padx=10, pady=10)
# 완수한 갯수
check_count = [cv1, cv2, cv3, cv4, cv5]
# 완수한 갯수에 따라 이미지 및 문구 변경
plant_image = [
PhotoImage(file="img/1.png"),
PhotoImage(file="img/2.png"),
PhotoImage(file="img/3.png"),
PhotoImage(file="img/4.png"),
PhotoImage(file="img/5.png"),
]
imgLabel = Label(plant_frame, image=plant_image[0])
imgLabel.pack(pady=(40, 10))
cheertxt = Label(plant_frame, text="시작", bg="white", fg="black")
cheertxt.pack()
def next_image():
count_list = []
for value in check_count:
count_list.append(value.get())
if count_list.count(1) <= 1:
imgLabel.configure(image=plant_image[0])
cheertxt.configure(text="시작")
elif count_list.count(1) == 2:
imgLabel.configure(image=plant_image[1])
cheertxt.configure(text="2개")
elif count_list.count(1) == 3:
imgLabel.configure(image=plant_image[2])
cheertxt.configure(text="3개")
elif count_list.count(1) == 4:
imgLabel.configure(image=plant_image[3])
cheertxt.configure(text="4개")
elif count_list.count(1) == 5:
imgLabel.configure(image=plant_image[4])
cheertxt.configure(text="5개")
plant_show = Button(
plant_frame,
text="식물",
command=next_image,
bg="cyan",
fg="black",
highlightbackground="cyan",
)
plant_show.pack()
win.mainloop() # 명령을 내려야-변수 뒤에 mainloop 함수 붙이기
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment