Fast way to create gui for bash app

28,640

Solution 1

I posted an answer here, that may be useful, for convenience I will just put it here again.

Yad may be useful in this regard, it is a fork of zenity with more features, one of them the ability to create forms.

Here is a very simple example of a form:

#!/bin/bash


frmdata=$(yad --title "Test Form" --form --field "Address" --field="Name")


frmaddr=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }')
frmname=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }')

echo $frmaddr > test.txt
echo $frmname >> test.txt

The above script will display a form like this:

enter image description here

After you enter your data and click ok or hit enter on the keyboard, the form data will be written to a text file called test.txt, I am using awk to separate the form data which is a string with a pipe as field separator, I believe there is a direct way to get the data without awk but I am no yad expert, please check the project home and ask questions, you may find a more elegant way.

How to get and install yad here:

http://www.webupd8.org/2010/12/yad-zenity-on-steroids-display.html

yad project home:

http://code.google.com/p/yad/

more examples here:

http://technostripe.com/yad-a-fork-of-zenity-with-more-features/

http://code.google.com/p/yad/wiki/Examples

There is no form designer for it yet but since the syntax is so simple and so close to zenity, that is not usually a problem.

Solution 2

For simple user-input you can use zenity (lives in the zenity package). A simple example might be something like this:

VARIABLE=$(zenity --entry --title="Give me inputz" --text="Write some stuff")
echo $VARIABLE

For a textarea (as we'd say in the HTML world), you'd change the syntax to something like this:

zenity --text-info --title="Give me inputz" --editable

You can find out a lot more from its manual. It's a very flexible little library user input in simple scripts.

Edit: You can also find some good examples over at Linuxaria.

Solution 3

Take a look at this: http://sites.google.com/site/easybashgui

You use:

source easybashgui
input 2 "Address" "?" "Name" "?"
cp "$dir_tmp/$file_tmp" "test.txt"
clean_temp
Share:
28,640

Related videos on Youtube

Matteo Pagliazzi
Author by

Matteo Pagliazzi

Updated on September 18, 2022

Comments

  • Matteo Pagliazzi
    Matteo Pagliazzi over 1 year

    I want to build a simple GUI for an app that use bash so for example clicking on a button would execute some bash commands and so one.

    There's a GUI creator also simple, i need only buttons and textareas that doesn't require to learn a new programming launguage?

  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    when i'm usg editable, can i sho others thing like text, buttons, how?
  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    wow it seems really cool but i can't find any type of docs...
  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    i would like to do something like that dl.dropbox.com/u/1143206/myImage.png, is possible?
  • Sabacon
    Sabacon over 12 years
    The developer site at the project home link has a lot of examples, and the developer himself is easy to talk to.
  • Sabacon
    Sabacon over 12 years
    Based on the examples and what I have read about Zenity and Yad I believe you can do similar,
  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    there are a lot of examples but hey aren't very useful at least for me, anyway now i'm emailing the developer...
  • Sabacon
    Sabacon over 12 years
    Good idea, the e-mail, maybe he or someone else will just give you the specific code you need.
  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    the main (only) problem i have now is that it's not possible to add something other then a textarea,for example a form followed by a textarea seem impossble to do
  • Sabacon
    Sabacon over 12 years
    I believe the text area can be in the form along with command buttons
  • Matteo Pagliazzi
    Matteo Pagliazzi over 12 years
    yes but only for 1 line, i want it to be bigger