Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can Python do that
#1
Hi everyone,
I am writing a program that should start a timer but while the timer isn't finished there should still be the possibility to input things and get an output is something like that possible in python?
Reply
#2
Yes, python can do this. Google "python event programming" or "python asynchronous programming".
Reply
#3
Yes, this is the code I wrote, it displays the time left, but it only counts down with seconds, not like 1m 30s... 1m 29s, and so on.
import time
sec=0

sec = int(input("hello! To how many seconds would you lke to set your timer to?"))
sec = sec + 1
for i in reversed(range(sec)):
    print(i)
    time.sleep(1)
Reply
#4
@RandomCoder: What the OP would like is, while the timer is counting the time, allow the user to enter some text, without stopping the timer.
Reply
#5
Um, you could still type on other programs while the python is still running, you do realize that, right?
Reply
#6
(Jan-07-2018, 03:01 PM)RandomCoder Wrote: Um, you could still type on other programs while the python is still running, you do realize that, right?

I believe he means in the same program. I ran your code (you don't need that "sec = 0", just fyi) and it does create a timer, but I can't interact with the program while it is counting down. I can still type in the console, but it has no effect on the program.

I believe what OP wants is something like a quiz program, where it might print a question and you only have 10 seconds to enter your input. I'm a noob, so I'm not sure how to accomplish this, though I imagine it would require at least one loop. I need to look into asynchronous Python, as @squensen mentioned.

[Edit] Just found this article on asynchronous programming. Starting to mess around with it right now.
Reply
#7
Well, I did what @hello_its_me wanted, I really don't have to do more with that, i just helped @hello_its_me and that is it really.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020