출력 된 시간을 24 시간에서 12 시간 형식으로 앞뒤로 전환하려고합니다. 시간은 텍스트로 gui에 ouputted입니다. 내 인터페이스와 버튼을 이미 만들었지 만 어떤 이유로 함수 호출이 올바르게 응답하지 않습니다.GUI에서 24 형식에서 12 시간으로 시간을 바꾼다.
import time
from tkinter import *
import os
class ConfigurationManagement():
def __init__(self):
self.__clockMode = 12
self.__clockColor = ''
self.__swapButtonTextColor = ''
self.__swapButtonColor = ''
def readClockSetting(self):
cwd = os.getcwd()
print(cwd)
filename = "clockSetting.txt"
setting = open(filename, 'r')
allSetting = setting.readlines()
setting.close()
return allSetting
def setClockMode(self, clockMode):
self.__clockMode = clockMode
def setClockColor(self, clockColor):
self.__clockColor = clockColor
def setSwapButtonTextColor(self, swapButtonTextColor):
self.__swapButtonTextColor = swapButtonTextColor
def setSwapButtonColor(self, swapButtonColor):
self.__swapButtonColor = swapButtonColor
def getClockMode(self):
return self.__clockMode
def settingUpClockSetting():
global clock
clock = ConfigurationManagement()
allSetting = clock.readClockSetting()
clock.setClockMode(allSetting[3])
clock.setClockColor(allSetting[6])
clock.setSwapButtonTextColor(allSetting[9])
def timeIn24(pastTime=''):
currentTime = time.strftime('%H: %M: %S')
if currentTime != pastTime:
digitalClock.config(text=currentTime)
digitalClock.after(200, timeIn24)
def timeIn12(pastTime=''):
currentTime = time.strftime('%I: %M: %S')
if currentTime != pastTime:
digitalClock.config(text=currentTime)
digitalClock.after(200, timeIn24)
def clockSwap():
print("Cat")
clockMode = clock.getClockMode()
if clockMode == 12:
clock.setClockMode(24)
timeIn24()
elif clockMode == 24:
clock.setClockMode(12)
timeIn12()
settingUpClockSetting()
root = Tk()
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root).pack(side=BOTTOM)
digitalClock = Label(topFrame, font=('times', 100, 'bold'), bg='black', fg='green')
digitalClock.pack()
timeIn12()
root.geometry('700x500')
timeSwapButton = Button(bottomFrame, text="24/12 Modes", fg="red", bg="black", command=clockSwap).pack()
root.mainloop()
---------- 디지털 시계 구성 파일 ----------
ClockType[12,24]:
12
ClockColor[The following colors can be handled: ]:
green
SwapButtonTextColor[The following colors can be handled ]:
red
SwapButtonColor[The following colors can be handled: ]:
black
I :이 지금까지 내 코드입니다
고양이 단추를 clockswap 함수에 추가하여 제 단추가 실제로 작동하는지 확인했습니다.
디버거 사용을 고려 했습니까? 또는 실패한 경우 clockswap() 함수에서 if의 두 가지 분기 내에서 지문을 추가하거나 clock.getClockMode()에서 반환 한 값을 인쇄하려고 시도 했습니까? 이 간단한 디버깅 옵션을 시도하지 않았다면 StackOverflow에서 어떤 질문을하고 계십니까? – barny
응답 해 주셔서 감사합니다. 실제로 문제는 잠시 나 자신을 수정하고 게시물에 새로운 대답을 추가했습니다. :); 상관없이 도와 줘서 고마워! –
문제의 적어도 일부는''clockSetting.txt ''설정 파일 처리와 관련이 있습니다. 예를 들어'allSetting [3]'이 정수 '12'가 아닌 '12 \ n '문자열로 설정되어 있습니다. – martineau