[Tutor] Input
dn
PythonList at DancesWithMice.info
Mon Apr 4 22:41:06 EDT 2022
On 05/04/2022 10.02, Megan Ani Mirkhanian wrote:
> Hi,
>
> I am writing a code to make my stepper motor back and forward.
> I wrote the code and then at the bottom I created a for loop which commands
> the stepper motor to go backwards and then forwards. I am trying to find a
> way to make the two for loops variables so that when I want to make the
> stepper motor go backwards I click on for instance x and enter and when I
> want the stepper motor to go forward I click on for instance y and enter.
> Is there a way to do this?
...
The easiest Python method is probably input():
direction = input("Which direction, x or y? ")
followed by an if-construct to call either forward_step() or
backward_step().
Some ideas: https://pynative.com/python-input-function-get-user-input/
You may prefer pygame or something similar (https://www.pygame.org/news)
which facilitate both mouse and keyboard interrogation - and in a
fashion which may be familiar to robot-control.
More complicated is the Curses library:
https://docs.python.org/3/howto/curses.html which is terminal-oriented.
The above page also mentions libraries which enable "cursor-addressable
text output and full support for mouse and keyboard input." - in case
the "click on" means that you want mouse-control.
Finally, there are GUIs such as tkinter and Qt...
--
Regards,
=dn
More information about the Tutor
mailing list