0

フォーマットを hh:mm:ss にする方法は? mm:ss:centisecond の代わりに?

import Tkinter as tk

def update_timeText():
    if (state):
        global timer
        timer[2] += 1

        if (timer[2] >= 100):
            timer[2] = 0
            timer[1] += 1
        if (timer[1] >= 60):
            timer[0] += 1
            timer[1] = 0
        timeString = pattern.format(timer[0], timer[1], timer[2])
        timeText.configure(text=timeString)
    root.after(10, update_timeText)

def start():
    global state
    state = True

def pause():
    global state
    state = False

def reset():
    global timer
    timer = [0, 0, 0]
    timeText.configure(text='00:00:00')

def exist():
    root.destroy()

state = False

root = tk.Tk()
root.wm_title('Simple Kitchen Timer Example')

timer = [0, 0, 0]
pattern = '{0:02d}:{1:02d}:{2:02d}'

timeText = tk.Label(root, text="00:00:00", font=("Helvetica", 150))
timeText.pack()

startButton = tk.Button(root, text='Start', command=start)
startButton.pack()

pauseButton = tk.Button(root, text='Pause', command=pause)
pauseButton.pack()

resetButton = tk.Button(root, text='Reset', command=reset)
resetButton.pack()

quitButton = tk.Button(root, text='Quit', command=exist)
quitButton.pack()

update_timeText()
root.mainloop()
4

3 に答える 3

3
# make: 00:00:00 stop watch timer format
def update_timeText():
  if (state):
    global timer
    timer[2] += 1
    if (timer[2] >= 60):
        timer[2] = 0
        timer[1] += 1
    if (timer[1] >= 60):
        timer[0] += 1
        timer[1] = 0
    timeString = pattern.format(timer[0], timer[1], timer[2])
    return timeString

# Step 1        
global state      
global timer    
state = True
timer = [0, 0, 0]
pattern = '{0:02d}:{1:02d}:{2:02d}'

# Step 2
print update_timeText()
print update_timeText()
print update_timeText()
print update_timeText()

出力:

00:00:01
00:00:02
00:00:03
00:00:04
于 2013-11-08T11:08:49.010 に答える
0

HR:MIN:SEC:CSEC が必要な場合は、次を使用します。

import Tkinter as tk

def update_timeText():
    if (state):
        global timer
        timer[2] += 1

        if (timer[2] >= 100):
            timer[2] = 0
            timer[1] += 1
        if (timer[1] >= 60):
            timer[0] += 1
            timer[1] = 0
        timeString = pattern.format(timer[0], timer[1], timer[2])
        timeText.configure(text=timeString)
    root.after(10, update_timeText)

def start():
    global state
    state = True

def pause():
    global state
    state = False

def reset():
    global timer
    timer = [0, 0, 0]
    timeText.configure(text='00:00:00')

def exist():
    root.destroy()

state = False

root = tk.Tk()
root.wm_title('Simple Kitchen Timer Example')

timer = [0, 0, 0]
pattern = '{0:02d}:{1:02d}:{2:02d}'

timeText = tk.Label(root, text="00:00:00", font=("Helvetica", 150))
timeText.pack()

startButton = tk.Button(root, text='Start', command=start)
startButton.pack()

pauseButton = tk.Button(root, text='Pause', command=pause)
pauseButton.pack()

resetButton = tk.Button(root, text='Reset', command=reset)
resetButton.pack()

quitButton = tk.Button(root, text='Quit', command=exist)
quitButton.pack()

update_timeText()
root.mainloop()
于 2014-12-16T17:27:14.667 に答える