G
G
gylah-u2021-11-14 02:13:36
Python
gylah-u, 2021-11-14 02:13:36

How to interact with the mouse in the Python terminal?

How can I control the mouse in terminal using python? For example, display some art in the terminal and do something with it using the mouse, or, for example, a button?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
javedimka, 2021-11-14
@gylah-u

A fairly new library for working with TUI (text user interface)
https://github.com/willmcgugan/textual

0
0nera, 2021-11-14
@0nera


pip3 install keyboard
First, install the Keystroke Handling library :

import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('q'):  # if key 'q' is pressed 
            print('You Pressed A Key!')
            break  # finishing the loop
    except:
        break  # if user pressed a key other than the given key the loop will break

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question