我用的是特金特和温森。
我希望声音和倒计时同时工作。
现在,一旦点击声音超过计时器就会出现。
我看过一些倒数计时器的例子,使用“after”。例:自我。之后(1000,自我。倒计时)。但我同时需要两者。
import tkinter as tk
from tkinter import Tk
from nBackTools.NBackTools import *
from nBackTools.ZBack import *
#To play sounds
import winsound
from winsound import *
import numpy as np
class NBack:
def __init__(self, master):
##Title of the window
self.master = master
master.title("N-Back")
##It measures the screen size (width x height + x + y)
##The opened window will be based on the screen size
master.geometry("{0}x{1}-0+0".format(master.winfo_screenwidth(), master.winfo_screenheight()))
self.canvas = tk.Canvas(master, width=master.winfo_screenwidth(), height=master.winfo_screenheight(), \
borderwidth=0, highlightthickness=0, bg="grey")
self.canvasWidth = master.winfo_screenwidth()
self.canvasHeight = master.winfo_screenheight()
##If removed, a white screen appears
self.canvas.grid()
"""
BREAK TIMER
"""
self.play()
self.canvas.create_text(((self.canvasWidth/2), (self.canvasHeight/2)-130), text="LET'S TAKE A BREAK!", font=(None, 90))
self.display = tk.Label(master, textvariable="")
self.display.config(foreground="red", background = "grey", font=(None, 70), text= "00:00")
self.display.grid(row=0, column=0, columnspan=2)
def play(self):
return PlaySound('clock_ticking.wav', SND_FILENAME)
root = Tk()
my_gui = NBack(root)
root.mainloop()