Probably at one point in your life, you will wake up wanting to create a GUI fast! whether it’s a front-end for some software you are writing, or just for the heck of it (i said probably). this simple how-to will teach you how to do just that.
The objective of this article is to design a GUI as fast and as effortlessly as possible. if you want more flashy GUI similar to what you usually get when you start a program, I’d recommend glade.
because we want the least effort we will be using bash (yes a terminal) to deploy and manage our GUI. The key player is xmessage (see “man 1 xmessage” for more detail). this is a simple yet incredibly useful program that displays a simple GUI dialog on the screen. its simplest form is:
xmessage "SIG is cool"
try that in your terminal and hit enter. if you did, you will see the following window:
see, even X thinks i’m cool :p
there are other futures that make xmessage more user friendly, and more usable. for instance, add the -default okay
switch to activate the okay button when you hit enter. also, you can load an entire text file in the text area by using -file
.
now, how about adding a few extra buttons? you can add more buttons by using the -buttons
switch. two buttons are added: “yes”, and “no”. “yes” is the default. the command:
xmessage "SIG is cool" -buttons "yes:10, no:11" -default yes
gives:
run it.
at this point you might be wondering how this can help make a robust GUI for your application. this is where bash really comes in. open a text editor and write the following:
xmessage -center "SIG is cool" -buttons "yes:10, no:11" -default yes answer=$? if [ $answer -eq 10 ]; then xmessage -center "You rock man" -default okay else xmessage -center ";_; ... i'm not crying ..." -default okay fi
this is a simple bash script that behaves in the following manner:
"SIG is cool" | +-> yes: "You rock man" | +-> no: ";_; ... i'm not crying ..."
first save your script as “sig.sh”. then add excution permissions:
cd /your/scripts/directory chmod +x sig.sh
once this has been done, simple start the script by issuing: (while still in the same directory)
./sig.sh
or you can double click, and choose run. any way you do it you should get the following:
SIGTERMer
Thanx for the awesome tutorial, but i think the last two images are not correct! just give’em a look! 🙂
just realized that your right 🙂 still not gonna change’m