1

Hi I was wondering if i could add buttons in my terminal using python as I am making a project and decided not to use tkinter and other GUI modules. Instead I wanted to do it in the python terminal and for your information I am using a MacBook.

I think that you can use the cursers module or something like so to make buttons just that I don't know how to do so :(

Thanks for any help provided! ;)

2
  • How can you add button to a interface which is text only Commented Jul 31, 2021 at 5:30
  • HI welcome to the community! Your question is overly broad for this site. Try looking into what packages would work for your application and give it a shot. If you have come across a specific issue, feel free to bring it up here. Commented Jul 31, 2021 at 5:42

2 Answers 2

1

in Python we can not create a button in the terminal and there is no way at all and only using graphical environments this is done which is not in the terminal You can do two things: a mouse and keyboard control with a click function, and if you do a Google search for this function, it will bring you Or put a text yourself, for example print (1- hello) And then define an input, such as go input And then define an if and say if go == 1: print (hello) There are two ways you can I hope this article is useful for you and you have answered your question

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Even though I did not get the answer I expected, I got a good and reasonable one! Thanks for your patience
0

Now you can use textual library. First install textual library.

pip install textual

Here is basic example of button with textual.

from textual.app import App, ComposeResult
from textual.widgets import Button, Static

class MyApp(App):
    def compose(self) -> ComposeResult:
        yield Static("Select an option:")
        yield Button("Start")
        yield Button("Settings")
        yield Button("Exit")

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.label == "Exit":
            self.exit()
        else:
            print(f"You pressed {event.button.label}")

MyApp().run()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.