1

我是编程新手,我正在尝试制作一种 typeracer 类型的程序,但是 while 循环与 simpledialog 中的其他按钮(包括关闭按钮)冲突,因此无法在不结束 main 的情况下中途退出。

import tkinter
from tkinter import simpledialog
from tkinter import messagebox
from datetime import datetime
import time
start = time.time()
answer = "She sells seashells on the seashore"
rounds = 1    
messagebox.showinfo("TypeRacer","Test your typing speed by typing various texts as fast as possible.")
while rounds != 3:
    question = simpledialog.askstring("Round "+str(rounds),answer)
    if question != answer:
        messagebox.showerror("Error!","Incorrect syntax")
    elif question == answer:
        messagebox.showinfo("You got it right!","Proceeding to the next round.")
        rounds += 1
end = time.time()
f1 = end - start
f2 = int(f1)
f2 = datetime.fromtimestamp(f2)
f3 = f2.strftime("%M:%S")
messagebox._show("Well done!","Your time was: "+str(f3))
4

0 回答 0