-2
このコードは、オフィスの開閉時間を設定するために使用され、4つの機能は開閉時間を増減します。このコードを1つの関数に結合する方法はありますか?
This is how it looks on the dashboard
closehour = 17
closeminute = 0
openhour = 8
openminute = 0
def increaseOpenTimeScript():
global openhour
global openminute
if openhour == 23 and openminute == 50:
openhour = 0
openminute = 0
time = "{}:{}0".format(openhour,openminute)
elif openminute == 50:
openminute = 0
openhour+=1
time = "{}:{}0".format(openhour, openminute)
else:
openminute+= 10
time = "{}:{}".format(openhour, openminute)
office.office1.officeOpenValue.config(text=time)
これは、機能の一つである、開放時間を減少させる閉鎖時間を増加させると終了時間を減少させることのような3以上です。 変更を簡単にするために、このコードをすべて1つの関数に結合したいと思います。ここで
すべての機能です:
def decreaseOpenTimeScript():
global openhour
global openminute
if openminute >= 10:
openminute -= 10
if openminute == 0:
time = "{}:{}0".format(openhour, openminute)
else:
time = "{}:{}".format(openhour,openminute)
elif openhour > 0 and openminute == 0:
openminute = 50
openhour -= 1
time = "{}:{}".format(openhour,openminute)
elif openhour == 0 and openminute == 0:
openhour = 23
openminute = 50
time = "{}:{}".format(openhour, openminute)
office.office1.officeOpenValue.config(text=time)
def increaseCloseTimeScript():
global closehour
global closeminute
if closehour == 23 and closeminute == 50:
closehour = 0
closeminute = 0
time = "{}:{}0".format(closehour,closeminute)
elif closeminute == 50:
closeminute = 0
closehour+=1
time = "{}:{}0".format(closehour,closeminute)
else:
closeminute+= 10
time = "{}:{}".format(closehour,closeminute)
office.office1.officeCloseValue.config(text=time)
def decreaseCloseTimeScript():
global closehour
global closeminute
if closeminute >= 10:
closeminute -= 10
if closeminute == 00:
time = "{}:{}0".format(closehour,closeminute)
else:
time = "{}:{}".format(closehour, closeminute)
elif closehour > 0 and closeminute == 0:
closehour-=1
closeminute = 50
time = "{}:{}".format(closehour,closeminute)
elif closehour == 0 and closeminute == 0:
closehour = 23
closeminute = 50
time = "{}:{}".format(closehour, closeminute)
office.office1.officeCloseValue.config(text=time)
すべての4つを投稿! –
まず、時間と分をargsとして関数に渡し、新しい(時、分)をタプルとして返します。 –
あなたは '' {:02}:{:02}」の書式(時、分) 'を探していますか? – Eric