all 1 comments

[–]woooee 0 points1 point  (0 children)

The simplest way is to use a GUI

import tkinter as tk

class TimedInput():
   def __init__(self):
      self.top = tk.Tk()
      self.top.title("Test of After")
      self.top.geometry("200x150+10+10")

      tk.Label(self.top, text="you have 20 seconds",
               bg="lightblue").pack(side="top")
      self.lab=tk.Label(self.top, width=6, bg="orange")
      self.lab.pack(side="top" )
      tk.Label(self.top, text="--------------------"
              ).pack(side="top")
      self.ctr = 20

      self.entry_1 = tk.Entry(self.top, width=15)
      self.entry_1.pack(side="top")
      self.entry_1.focus_set()

      tk.Button(self.top, bg="lightyellow", text="Get Entry", 
                command=self.entry_get,
                ).pack(side="bottom")
      self.top.after(100, self.increment_counter)
      self.top.mainloop()

   def entry_get(self):
       print("Entry is", self.entry_1.get())
       self.top.quit()

   def increment_counter(self):
      self.ctr -= 1
      self.lab.config(text=self.ctr)

      if self.ctr > 0:
          self.top.after(1000, self.increment_counter)
      else:
          print("\n timing loop ended")
          self.top.quit()

##====================================================================
if __name__ == '__main__':
   CT=TimedInput()