Skip to main content

Easily create terminal user interface containing menus, text boxes and input fields for your projects

Project description

MyTUI

Terminal User Interface in Python

Project Description


Copyright (c) 2022 Paulin-Dev.

Contact (Discord) : Pekkos#9809

MyTUI simplies for both users and developers terminal experience. It is inspired by the interface of the Rasberry Pi Software Configuration Tool (raspi-config). It is fully responsive to work with any terminals' size. It provides quick-to-implement functions to create interfaces such as :

  • Text Boxes
  • Menus
  • Input Fields
  • Yes/No Choice

Please note that it is still in development. There is no guarantee that everything will perfectly work.

If you have issues or ideas for this package, please contact the author.

Requirements


Python 3 (not tested under version 3.6)

getkey Package to get user's input


Getting started


You won't need to import extra modules to make it work, simply import the MyTUI class and use its methods to create interfaces. These methods will return the output if there is one. You can then use the user's response to do whatever you want.

Examples


As already mentioned, there are 4 different types of interface available at the moment plus the configuration. Here is how to use them.

Config

You can use the config method to configurate some options.

from mytui import MyTUI

MyTUI.config(
    text_center=True,
    can_quit=True,
    quit_key='q'
)

You can always change this later
The quit key will exit the program. The back string will be returned if the user presses escape.


Text Box

This is the most basic interface, it creates a simple text box with its title and text. Press Enter to exit.
It returns None.

from mytui import MyTUI

MyTUI.textbox(title="Your Title", text="Your text")

you can use \n in the text fields

Output :

Text Box Image



Menu

You can use menus to create a list of options. Use the up and down arrows to navigate.
It returns the name (str) of the selected option.

from mytui import MyTUI

options = [
    '1. First option',
    '2. Second option',
    '3. Third option'
]

selected = MyTUI.menu(title="Your Title", text="Your text", options=options)

if selected == options[0]:
    # do stuff

Output :

Menu Image



Yes/No Choice

The yes/no interface is basically used to ask yes/no questions the targeted user. Use the left and right arrows or tab to navigate.
It returns True (bool) if the selected answer is "yes" else False.

from mytui import MyTUI

if MyTUI.yesno(title="Your Title", text="Your question"):
    # do stuff
else:
    # do other stuff

Output :

Yes/No Image



Input

Last interface but not least : input fields. You can create input fields to recover a value from your user. All parameters are optional. Press Enter to submit your answer.
It returns the value (str) inside the input field.

from mytui import MyTUI

output = MyTUI.input(
    title="Your Title",
    text="Your text",
    default_text="",
    input_size=60,
    max_length=50,
    min_length=0,
    can_delete_default_text=False,
    allow_spaces=True,
    only_numeric=False,
    only_alpha=False
)

Output :

Input Image



Copyright


MIT License

Copyright (c) 2022 Paulin-Dev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MyTUI-1.0.0.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

MyTUI-1.0.0-py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page