我想每秒播放一次滴答声,但是时间是基于算法的。
我尝试过
def sound(self):
if self.second_display == 1.0:
windsound.PlaySound("tock", winsound.SND_FILENAME)
但不起作用
tock.wav
也已经与代码位于同一文件夹
TICK_TIME = 2**6
def display(self):
self.seconds = self.time // 60
self.minutes=self.seconds//60
self.hour_display = self.minutes // 60
self.minute_display = self.minutes % 60
self.second_display = self.seconds % 60
self.millisecond_display = self.time % 60
self.alltime = self.hour_display, self.minute_display,
self.second_display, self.millisecond_display
self.alltime2 = [self.hour_display, self.minute_display,
self.second_display, self.millisecond_display]
self.LDCDisplay.display("%02d:%02d:%02d.%02d" % (self.alltime))
def sound(self):
if self.second_display == 1.0:
windsound.PlaySound("tock", winsound.SND_FILENAME)
def do_start(self):
if self.onRunning == False:
self.onRunning=True
self.StartButton.setText("PAUSE")
self.timer.start(1)
self.StartButton.clicked.connect(self.do_pause)
def tick(self):
self.time += TICK_TIME/1000
self.display()
def do_reset(self):
if self.onRunning==False:
self.LDCDisplay.display("00:00:00.00")
self.time=0
elif self.onRunning==True:
self.time=0
self.tableWidget.setRowCount(0)
self.Milli.clear()
self.x = 0
def do_pause(self):
if self.onRunning==True:
self.onRunning=False
self.timer.stop()
self.StartButton.setText("START")
self.StartButton.clicked.connect(self.do_start)