Arrow key controlled Python menu - python

I'm trying to create a terminal based program that starts with a main menu. I would like the user to be able to press the up and down keys to highlight each of the options. This can just be done by reprinting the menu. And once this is done the user should be able to press enter to select the option triggering another section of code. At the moment I'm having trouble getting the program to see when I'm pressing the up and down keys. Any help with this world be appreciated.
I am happy to include pygame in the program so long as I don't have to start up the graphical window.
Thanks in advance

Related

How can i simulate a pressed button with the enter key in pyqt5

my goal is to launch a function in python by simply clicking on the enter key on my keyboard instead of the push button (using Qtdesigner). To put you in context, I have a barcode scanner, this one will read the code and write it in a lineEdit, the scanner is programmed to press enter directly, I would like to take this opportunity to perform my search function instead of clicking the button.
I hope I was clear, you can contact me for more information. Thank you in advance dear community.

How to not immediately refresh after user input curses

I am writing a DoodleJump game for the terminal in Python with curses. I use getch() to get the user input to know in which direction the character should move. When I get the user input my environment gets updated simultaneously but I want that it just keeps on moving and not update when I get the user input.
Does anybody know how I can achieve this? I tried using nodelay() but that still doesn't cut it. Thanks in advance
please try with:
time.sleep(seconds)
This will wait the seconds you want before continue.
Sources:
https://www.pythoncentral.io/pythons-time-sleep-pause-wait-sleep-stop-your-code/
Hope it help, have a nice day,
David.
curses refreshes the window associated with getch. You could prevent refreshes (or hide them) by turning off echo, and using a window that won't have changes made to it (even one that you create just for that purpose).

Pygame window wont move or close after using tkinter

I have had this problem for ages now with many different projects now, so I really want to find out how to fix it. For example, in one of my projects, I created a level editor for a game. The level editor had the option to save and load different levels from a file using tkinter.filedialog.
Now after I select the file, the game will still work, but the 'X' close button doesn't work anymore, and I can't move the window.
The game itself works as usual, and I can still interact with everything inside of the window, but I can't move or close the window.
Thanks in advance.
Ok. I figured this one out. The problem went away when I called the tkinter functions from a key press, not a mouse press.

WxPython exit button doesn´t always works

I am using a code designed by another person in MAC OS. I am using Windows instead and have slightly modified it, but the problem comes when using the GUI that is created.
I have already dealt with a similar issue with a slider. Once I pressed the slider, I couldn´t release it or press another button. I was forced to quit the GUI and start again. I solved it by changing the event command from EVT_COMMAND_SCROLL to EVT_COMMAND_SCROLL_THUMBTRACK. However I did not understand why it worked in MAC OS and does not work in Windows.
Now, I want to close the GUI with the typical cross inside the red button in the right corner of the window. I can do it if it is the first order I do in the GUI. If I first press any button or slider, the exit button does not work.
It made me consider if a major problem is hidden in the code which I am not seeing. I am new at wxPython, which is the module used in the code.
I just ask for your opinion and hope it is a basic error.
Thanks very much

How do I send key presses and mouse movements to an application running in the background? (In Python)

Ok, so what I want to do is allow my program to send mouse movements and keypresses (both mouse and keyboard) to a particular task without having to be tabbed into the task so I can do other things on my computer with the mouse and keyboard while the task runs. Is it possible to do this relatively simply with existing python modules?
example of what I want to do:
task='application name'
task.leftclick
task.moveX(int)
task.moveY(int)
task.keypress(r)
All while being able to use my mouse and keyboard normally on a different application.
Thanks for the help in advance!
(Python3.6)
For anyone who happens upon this post, I found https://pypi.org/project/ahk/ I haven't looked into it fully but either you can use this or create an auto hotkey script and just call that with you python code to achieve what I wanted to do in the question.

Categories

Resources