1

I'm new to programming and I'm trying to make a typeracer kind of program but the while loop conflicts with other buttons in simpledialog(including the close button), making it impossible to quit halfway without ending the 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))
Mamon4
  • 11
  • 1
  • 1
    Consider whether you really want the interface to work this way for a typing test. Doing it this way, it will count time that the user spends dismissing the dialog boxes, positioning the insertion point in the new dialog, etc. – Karl Knechtel May 18 '21 at 22:21
  • Anyway, it's not really clear to me what you mean by "interfere" or "quit" here; but you should look up the concept of a dialog box being *modal* in the documentation. – Karl Knechtel May 18 '21 at 22:22
  • I don't understand what you try to do and what is the problem (i didn't run code) but usually any loop is wrong idea in any GUI (not only in `tktiner`) because it blocks `mainloop()` which handles all events and widgets. maybe you should use one standrad window and display message in `Label` inside window. – furas May 18 '21 at 22:58
  • Thank you for the comments. So is it better if I make my own dialogs? I tried looking it up and I think making my own dialog should fix it. I think. – Mamon4 May 20 '21 at 17:24

0 Answers0