Hi
My question is: i made a program that counts up and up continuously in the background but i want it to print what number it is up to when you press a certain button such as ENTER. I have tried using raw_inputs() but all that happens is it keeps waiting every time for an input rather then just continuing counting like it is meant to. Any help would be greatly appreciated.
lllllIllIlllI
178
Veteran Poster
Recommended Answers
Jump to PostIf you are using Windows you can do this:
# get the character of a key pressed (no return key needed) # works only in the command window and with Windows OS from msvcrt import getch print "press a char key (escape key to exit)" while True: …
Jump to PostWell you could just use a Thread object to do the counting for you and then in your main program everytime the user enters a key, you just call a function of the Thread object counting that returns it's current value.
The example below might help.
All 6 Replies
sneekula
969
Nearly a Posting Maven
lllllIllIlllI
178
Veteran Poster
a1eio
16
Junior Poster
vegaseat
commented:
Very nice solution
+8
lllllIllIlllI
178
Veteran Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
a1eio
16
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.