Python Forum
Problem with input after function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with input after function
#5
Hi ghoul, the situation is the following:

[Image: 00.png]

the code in this case is the following:

    
def intro_menu():
    intro_menu_create()
    keyboard.add_hotkey('up', intro_menu_key_up)
    keyboard.add_hotkey('down', intro_menu_key_down)
    keyboard.add_hotkey('space', intro_menu_key_enter)
    keyboard.wait()

def intro_menu_create():
    global intro_index_selected

    intro_menu = ["Accedi", "Registrati", "Esci"]

    cls()
    ascii_art()
    print("\n" * 3)

    print(" Accedi \ Registrati")
    for i in range(1, 4):
        print("{1} {0} {2}".format(intro_menu[i-1], ">" if intro_index_selected == i else " ", "<" if intro_index_selected == i else " "))

def intro_menu_key_up():
    global intro_index_selected
    if intro_index_selected == 1:
        return
    intro_index_selected -= 1
    intro_menu_create()

def intro_menu_key_down():
    global intro_index_selected
    if intro_index_selected == 3:
        return
    intro_index_selected += 1
    intro_menu_create()

def intro_menu_key_enter():
    global intro_index_selected
    
    if intro_index_selected == 1:
        login_form()
    elif intro_index_selected == 2:
        registration_form()
    else:
        exit()
In this "menu function" when user press 'up' or 'down' keys,
the cursors '>' and '<' moves up and down to previous or following
menu item in according to the index "intro_index_selected" value, updating the print.

In this function for wait and catch the key pressed by the user i call the keyboard.wait() function.
When user press Enter key, thru the function "keyboard.add_hotkey('enter', intro_menu_key_enter)"
the relative function is called as shown below:

def intro_menu_key_enter():
    global intro_index_selected
    
    if intro_index_selected == 1:
        login_form()
    elif intro_index_selected == 2:
        registration_form()
    else:
        exit()
Now the problem exist when i call login_form() after have obtained
the 'enter' key thru keyboard.add_hotkey('enter', intro_menu_key_enter).

The login_form() was correctly called, but the first input was just "auto-validate" with empty value,
meanwhile is just possible to write in the second input.

If I choose another key instead of 'enter', it works properly ..
I've no idea where I could looking for the solution Shifty
Reply


Messages In This Thread
Problem with input after function - by luilong - Nov-27-2021, 08:14 PM
RE: Problem with input after function - by luilong - Nov-28-2021, 12:19 AM
RE: Problem with input after function - by ghoul - Nov-28-2021, 10:52 AM
RE: Problem with input after function - by luilong - Nov-28-2021, 11:13 PM
RE: Problem with input after function - by luilong - Nov-29-2021, 08:53 PM
RE: Problem with input after function - by luilong - Nov-29-2021, 10:55 PM
RE: Problem with input after function - by luilong - Dec-04-2021, 12:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,167 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  problem in using input command akbarza 4 1,274 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 701 Oct-18-2023, 08:16 AM
Last Post: akbarza
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,171 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Showing an empty chart, then input data via function kgall89 0 1,008 Jun-02-2022, 01:53 AM
Last Post: kgall89
  input function question barryjo 12 2,886 Jan-18-2022, 12:11 AM
Last Post: barryjo
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,277 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Exit function from nested function based on user input Turtle 5 3,030 Oct-10-2021, 12:55 AM
Last Post: Turtle
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 2,024 Oct-06-2021, 09:39 AM
Last Post: menator01
  Input function cutting off commands at spaces. throwaway34 3 2,265 May-12-2021, 06:40 AM
Last Post: throwaway34

Forum Jump:

User Panel Messages

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