Python Forum
Have an amount of time to perform and action
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Have an amount of time to perform and action
#1
Hello,

I am working on a project that I need to be able to see if you entered the correct passcode in 10 seconds. I have gotten the part to detect if you have entered the correct passcode but can no find out how to make print "you got the code right" if you do enter it in that amount of time and make it print "wrong passcode" if you do not enter any passcode in the 10 seconds or if you do not get the right passcode in that 10 seconds.

Any help would be greatly appreciated, thanks
Reply
#2
A simple way to ask for data with a timeout in a console application:
import datetime as dt
import selectors
import sys

def main():
    sel = selectors.DefaultSelector()
    sel.register(sys.stdin, selectors.EVENT_READ)
    print("Enter passcode: ", end='')
    sys.stdout.flush()
    pairs = sel.select(timeout=5)
    if pairs:
        passcode = sys.stdin.readline().strip()
        print('you entered:', passcode)
    else:
        print('\ntimed out')

if __name__ == '__main__':
    main()
A problem with the previous code is that it doesn't hide the passcode. The standard module to hide the password is 'getpass', but it doesn't have a timeout. Now it depends on your framework: which version of python, which OS, are you using a GUI toolkit? GUI toolkits such as tkinter have entry fields that can hide their contents for example and they also have timers. Do you have some code to show?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pixel color and action Sartre 4 2,113 Apr-13-2023, 03:26 AM
Last Post: Sartre
Question Running an action only between certain times alexbca 9 1,735 Mar-15-2023, 04:21 PM
Last Post: deanhystad
  Checkbox itens with a button to run action Woogmoog 3 958 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
Question Running an action only if time condition is met alexbca 5 1,321 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Get amount of bytes in a file chesschaser 1 1,582 Aug-23-2021, 03:24 PM
Last Post: deanhystad
  Taking serial data to perform key.press functions ausbollinger13 1 2,324 Sep-04-2020, 10:26 PM
Last Post: bowlofred
  Moving large amount of data between MySql and Sql Server using Python ste80adr 4 3,436 Apr-24-2020, 01:24 PM
Last Post: Jeff900
  SQL query with a variable amount of parameters Antares 10 6,888 Jul-08-2019, 02:24 PM
Last Post: Antares
  action on MQTT while long loop is running runboy 4 6,112 Oct-05-2018, 11:57 PM
Last Post: runboy
  Why I get RecursionError on very small amount of data? wavic 3 3,954 Aug-05-2018, 04:55 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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