from tkinter import *#window from tkinter import ttk from io import StringIO from datetime import datetime
root = Tk() root.title("GUI") root.minsize(230,215) def bedtime_from_now(H,M, eol=True): #global now Hnow = now.hour Mnow = now.minute
if M >= Mnow: M2 = M - Mnow else: M2 = 60 - Mnow + M Hnow = Hnow + 1 if Hnow >= 24: Hnow = Hnow - 24 if H >= Hnow: H2 = H - Hnow else: H2 = 24 - Hnow + H print(" ({:02}시간 {:02}분 후)".format(H2, M2),file=sio,end='') if eol==True: print(file=sio) def bed_time(h,m=0,eol=True): if m==0: H = (hour - h + 24) % 24 M = 0 else: if minute - m >= 0: M = minute - m H = (hour - h + 24) % 24 else: M = (minute - m + 60) % 60 H = (hour-1 - h + 24) % 24
print("{:02}시 {:02}분".format(H,M),file=sio,end='') bedtime_from_now(H,M,eol) def click(): #global strs3 global hour ,minute global now #global sio sio.seek(0) sio.truncate(0) now = datetime.now() hour = int(strs.get()) minute = int(strs2.get()) print ("현재시각 {}시 {:02}분\n".format(now.hour,now.minute),file=sio) print("잠자리에 들 시간",file=sio) bed_time(3) bed_time(4, 30) bed_time(6) bed_time(7, 30) bed_time(8, 30) bed_time(9,m=0,eol=False) strs3.set(sio.getvalue()) #end def strs = StringVar() strs2 = StringVar() strs3 = StringVar() lbl = Label(root,text="일어날 시간을 입력하세요") lbl.grid(row=0,column=1,padx=5,pady=5)
lbl2 = Label(root, text=" 시") lbl2.grid(row=1, column=0,pady=5,padx=5)
Combx1 = ttk.Combobox(textvariable=strs, width=20) Combx1['value'] = tuple(str(i) for i in range(0, 23 +1, 1)) #콤보박스 요소 삽입 Combx1.current(0) Combx1.grid(row=1,column=1,pady=5)
lbl3 = Label(root, text=" 분") lbl3.grid(row=3, column=0)
Combx2 = ttk.Combobox(textvariable=strs2, width=20) Combx2['value'] = tuple(str(i) for i in range(0,55+5,5)) #콤보박스 요소 삽입 Combx2.current(0) Combx2.grid(row=3,column=1)
btn = Button(root, text="확인",command=click,width=6,height=1, bg='#cae1ff') btn.grid(row=4,column=1,pady=10) sio = StringIO("")
strs3.set("잠자리에 들 시간") lbl4 = Label(root, textvariable=strs3) lbl4.grid(row=5, column=1,pady=7) root.mainloop() sio.close()
|