Fast way to create gui for bash app
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:
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:
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
Related videos on Youtube
Matteo Pagliazzi
Updated on September 18, 2022Comments
-
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 over 12 yearswhen i'm usg editable, can i sho others thing like text, buttons, how?
-
Matteo Pagliazzi over 12 yearswow it seems really cool but i can't find any type of docs...
-
Matteo Pagliazzi over 12 yearsi would like to do something like that dl.dropbox.com/u/1143206/myImage.png, is possible?
-
Sabacon over 12 yearsThe developer site at the project home link has a lot of examples, and the developer himself is easy to talk to.
-
Sabacon over 12 yearsBased on the examples and what I have read about Zenity and Yad I believe you can do similar,
-
Matteo Pagliazzi over 12 yearsthere are a lot of examples but hey aren't very useful at least for me, anyway now i'm emailing the developer...
-
Sabacon over 12 yearsGood idea, the e-mail, maybe he or someone else will just give you the specific code you need.
-
Matteo Pagliazzi over 12 yearsthe 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 over 12 yearsI believe the text area can be in the form along with command buttons
-
Matteo Pagliazzi over 12 yearsyes but only for 1 line, i want it to be bigger