{"id":12435,"date":"2019-03-27T00:59:50","date_gmt":"2019-03-27T00:59:50","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12435"},"modified":"2019-03-27T00:59:50","modified_gmt":"2019-03-27T00:59:50","slug":"gtkdialog-create-graphical-gtk-interfaces-and-dialog-boxes-using-shell-scripts-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/gtkdialog-create-graphical-gtk-interfaces-and-dialog-boxes-using-shell-scripts-in-linux\/","title":{"rendered":"Gtkdialog \u2013 Create Graphical (GTK+) Interfaces and Dialog Boxes Using Shell Scripts in Linux"},"content":{"rendered":"<p><b>Gtkdialog<\/b>\u00a0(or gtkdialog) is an open source nifty utility for creating and building GTK+ Interfaces and Dialog Boxes with the help of Linux shell scripts and using GTK library, as well as using an xml-like syntax, which makes easy to create interfaces using gtkdialog. It is much similar to most famous tool called Zenity, but it comes with some useful customizable features that enables you to easily create many widgets like vbox, hbox, button, frame, text, menu, and a lot more.<\/p>\n<div id=\"attachment_7931\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7931\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog.jpeg\" alt=\"Install Gtkdialog in Linux\" width=\"507\" height=\"348\" aria-describedby=\"caption-attachment-7931\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7931\" class=\"wp-caption-text\">Create Gtkdialog Boxes in Linux<\/p>\n<\/div>\n<p><b>Read Also<\/b>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/zenity-creates-graphical-gtk-dialog-boxes-in-command-line-and-shell-scripts\/\" target=\"_blank\" rel=\"noopener\">Create GTK+ Graphical Dialog Boxes using Zenity<\/a><\/p>\n<h3>Installation of Gtkdialog in Linux<\/h3>\n<p>You can download\u00a0<a href=\"https:\/\/code.google.com\/p\/gtkdialog\/downloads\/list\" target=\"_blank\" rel=\"nofollow noopener\">gtkdialog-0.8.3<\/a>\u00a0(which is is the latest version) or you may also use wget command, unpack the downloaded file and run these following commands to compile from source.<\/p>\n<pre>$ sudo apt-get install build-essential\t\t[on <b>Debian<\/b> based systems]<\/pre>\n<pre># yum install gcc make gcc-c++\t\t\t[on <b>RedHat<\/b> based systems]<\/pre>\n<pre>$ wget https:\/\/gtkdialog.googlecode.com\/files\/gtkdialog-0.8.3.tar.gz\r\n$ tar -xvf gtkdialog-0.8.3.tar.gz\r\n$ cd gtkdialog-0.8.3\/\r\n$ .\/configure\r\n$ make\r\n$ sudo make install<\/pre>\n<p>Now let\u2019s start creating some boxes, create a new \u201c<b>myprogram<\/b>\u201d script in your home folder.<\/p>\n<h5>My First Program<\/h5>\n<pre>$ cd\r\n$ touch myprogram<\/pre>\n<p>Now open the \u201c<b>myprogram<\/b>\u201d file using any text editor you want, and add the following code to it.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nGTKDIALOG=gtkdialog \r\nexport MAIN_DIALOG=' \r\n\r\n&lt;window title=\"My First Program\" icon-name=\"gtk-about\" resizable=\"true\" width-request=\"300\" height-request=\"310\"&gt; \r\n\r\n&lt;vbox&gt; \r\n\t&lt;hbox space-fill=\"true\" space-expand=\"true\"&gt; \r\n\t\t&lt;button&gt;\t \r\n\t\t\t&lt;label&gt;Welcome to TecMint.com Home!&lt;\/label&gt; \r\n\t\t\t&lt;action&gt;echo \"Welcome to TecMint.com Home!\"&lt;\/action&gt; \r\n\t\t&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n&lt;\/vbox&gt; \r\n&lt;\/window&gt; \r\n' \r\n\r\ncase $1 in \r\n\t-d | --dump) echo \"$MAIN_DIALOG\" ;; \r\n\t*) $GTKDIALOG --program=MAIN_DIALOG --center ;; \r\n\r\nesac \r\n------------<\/pre>\n<p>Save the file, and set execute permission and run it as shown.<\/p>\n<pre>$ chmod 755 myprogram\r\n$ .\/myprogram<\/pre>\n<p>This is how your first program created and executed using gtkdialog.<\/p>\n<div id=\"attachment_7927\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-program.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-7927\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-program-620x446.jpeg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-program-620x446.jpeg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-program.jpeg 796w\" alt=\"Gtkdialog Program\" width=\"620\" height=\"446\" aria-describedby=\"caption-attachment-7927\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7927\" class=\"wp-caption-text\">Gtkdialog Program<\/p>\n<\/div>\n<p>Now, we will explain the code in short.<\/p>\n<ol>\n<li><b>#!\/bin\/bash<\/b>: The first line of any shell script, it is used to specify the bash shell path.<\/li>\n<li><b>GTKDIALOG = gtkdialog<\/b>: Here we defined a variable to use it later when executing the shell script with gtkdialog, this line must be in all scripts that you create using gtkdialog.<\/li>\n<li><b>export MAIN_DIALOG=<\/b>: Another variable we defined which will contain all syntax for our interface, you can replace MAIN_DIALOG with any name you want, but you have to replace it also in last 4 lines of the script.<\/li>\n<li><b>Window Title<\/b>: I don\u2019t think that this code need to be explained, we created a title, a default icon for the window, we choose if it was resizable or not, and we defined the width and height we want, of course all of those options are secondary, you can just use the\u00a0<b>&lt;window&gt;<\/b>\u00a0tag if you want.<\/li>\n<li><b>&lt;vbox&gt;<\/b>\u00a0: We use the vbox tag to create a vertical box, it is important to create a vbox tag in order to contain other tags such as hbox and button, etc.<\/li>\n<li><b>&lt;hbox&gt;<\/b>: Here we created a horizontal box using the &lt;hbox&gt; tag, \u201cspace-fill\u201d and \u201cspace-expand\u201d are options to expand the hbox through the window.<\/li>\n<li><b>&lt;button&gt;<\/b>: Create a new button.<\/li>\n<li><b>&lt;label&gt;<\/b>: This is the default text for the button, we closed the label tag using &lt;\/label&gt;, of course it is very important to close all the tags that we use.<\/li>\n<li><b>&lt;action&gt;<\/b>: This what happens when the button is clicked, you can run a shell command if you want or execute any other file if you want, there are many other actions and signals as well, don\u2019t forget to close it using &lt;\/action&gt;.<\/li>\n<li><b>&lt;\/button&gt;<\/b>: To close the button tag.<\/li>\n<li><b>&lt;\/hbox&gt;<\/b>: To close the hbox tag.<\/li>\n<li><b>&lt;\/window&gt;<\/b>: To close the window tag.<\/li>\n<\/ol>\n<p>The last 4 lines must also be in all shell scripts that you create using gtkdialog, they execute the MAIN_DIALOG variable using gtkdialog command with the \u2013center option to center the window, very useful in fact.<\/p>\n<h5>My Second Program<\/h5>\n<p>Similarly, create a another file and call it as \u2018<strong>secondprogram<\/strong>\u2018 and add the following whole content to it.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nGTKDIALOG=gtkdialog \r\nexport MAIN_DIALOG=' \r\n\r\n&lt;window title=\"My Second Program\" icon-name=\"gtk-about\" resizable=\"true\" width-request=\"250\" height-request=\"150\"&gt; \r\n\r\n&lt;vbox&gt; \r\n\t&lt;hbox space-fill=\"true\"&gt; \r\n\t\t&lt;combobox&gt;\t \r\n\t\t\t&lt;variable&gt;myitem&lt;\/variable&gt; \r\n\t\t\t&lt;item&gt;First One&lt;\/item&gt; \r\n\t\t\t&lt;item&gt;Second One&lt;\/item&gt; \r\n\t\t\t&lt;item&gt;Third One&lt;\/item&gt; \r\n\t\t&lt;\/combobox&gt; \r\n\t&lt;\/hbox&gt; \r\n\t&lt;hbox&gt; \r\n\t\t&lt;button&gt; \r\n\t\t\t&lt;label&gt;Click Me&lt;\/label&gt; \r\n\t\t\t&lt;action&gt;echo \"You choosed $myitem\"&lt;\/action&gt; \r\n\t\t&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n&lt;hseparator width-request=\"240\"&gt;&lt;\/hseparator&gt; \r\n\r\n\t&lt;hbox&gt; \r\n\t\t&lt;button ok&gt;&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n&lt;\/vbox&gt; \r\n&lt;\/window&gt; \r\n' \r\n\r\ncase $1 in \r\n\t-d | --dump) echo \"$MAIN_DIALOG\" ;; \r\n\t*) $GTKDIALOG --program=MAIN_DIALOG --center ;; \r\n\r\nesac<\/pre>\n<p>Save the file, set execute permission on it and run it as shown.<\/p>\n<pre>$ chmod 755 secondprogram\r\n$ .\/secondprogram<\/pre>\n<div id=\"attachment_7928\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-select.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7928\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-select.jpeg\" alt=\"Gtkdialog Select Box\" width=\"507\" height=\"348\" aria-describedby=\"caption-attachment-7928\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7928\" class=\"wp-caption-text\">Gtkdialog Select Box<\/p>\n<\/div>\n<p>Now, we will explain the code in short.<\/p>\n<ol>\n<li>We create a combobox widget using &lt;combobox&gt;, the &lt;variable&gt; tag is the default name of the variable which the chosen item will be stored in, we used this variable to print the selected item later using echo.<\/li>\n<li><b>&lt;hseparator&gt;<\/b>\u00a0is a horizontal separator, you can set the default width for it using width-request option.<\/li>\n<li><b>&lt;button ok&gt;&lt;\/button&gt;<\/b>\u00a0is an OK button that will close the window just when you click it, it is very useful so we don\u2019t need to create a custom button to do that.<\/li>\n<\/ol>\n<h5>My Third Prgoram<\/h5>\n<p>Create another file called\u00a0<strong>\u2018thirdprogram<\/strong>\u2018 and add the whole bunch of code to it.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nGTKDIALOG=gtkdialog \r\nexport MAIN_DIALOG=' \r\n\r\n&lt;window title=\"My Second Program\" icon-name=\"gtk-about\" resizable=\"true\" width-request=\"250\" height-request=\"150\"&gt; \r\n\r\n&lt;notebook tab-label=\"First | Second|\"&gt; \r\n&lt;vbox&gt; \r\n\t&lt;hbox space-fill=\"true\"&gt; \r\n\t\t&lt;combobox&gt;\t \r\n\t\t\t&lt;variable&gt;myitem&lt;\/variable&gt; \r\n\t\t\t&lt;item&gt;First One&lt;\/item&gt; \r\n\t\t\t&lt;item&gt;Second One&lt;\/item&gt; \r\n\t\t\t&lt;item&gt;Third One&lt;\/item&gt; \r\n\t\t&lt;\/combobox&gt; \r\n\t&lt;\/hbox&gt; \r\n\t&lt;hbox&gt; \r\n\t\t&lt;button&gt; \r\n\t\t\t&lt;label&gt;Click Me&lt;\/label&gt; \r\n\t\t\t&lt;action&gt;echo \"You choosed $myitem\"&lt;\/action&gt; \r\n\t\t&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n&lt;hseparator width-request=\"240\"&gt;&lt;\/hseparator&gt; \r\n\r\n\t&lt;hbox&gt; \r\n\t\t&lt;button ok&gt;&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n&lt;\/vbox&gt; \r\n\r\n&lt;vbox&gt; \r\n\r\n\t&lt;hbox space-fill=\"true\"&gt; \r\n\t\t&lt;text&gt; \r\n\t\t&lt;label&gt;Spinbutton &lt;\/label&gt; \r\n\t\t&lt;\/text&gt; \r\n\t&lt;\/hbox&gt; \r\n\r\n\t&lt;hbox space-fill=\"true\" space-expand=\"true\"&gt; \r\n\t\t&lt;spinbutton range-min=\"0\" range-max=\"100\" range-value=\"4\"&gt; \r\n\t\t\t&lt;variable&gt;myscale&lt;\/variable&gt; \r\n\t\t\t&lt;action&gt;echo $myscale&lt;\/action&gt; \r\n\t\t&lt;\/spinbutton&gt; \r\n\t&lt;\/hbox&gt; \r\n\r\n\t&lt;hbox&gt; \r\n\t\t&lt;button ok&gt;&lt;\/button&gt; \r\n\t&lt;\/hbox&gt; \r\n\r\n&lt;\/vbox&gt; \r\n&lt;\/notebook&gt; \r\n&lt;\/window&gt; \r\n' \r\n\r\ncase $1 in \r\n\t-d | --dump) echo \"$MAIN_DIALOG\" ;; \r\n\t*) $GTKDIALOG --program=MAIN_DIALOG --center ;; \r\n\r\nesac<\/pre>\n<p>Save the file, grant execute permission and fire it as shown.<\/p>\n<pre>$ chmod 755 thirdprogram\r\n$ .\/thirdprogram<\/pre>\n<div id=\"attachment_7929\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-dropdown-1.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7929\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-dropdown-1.jpeg\" alt=\"Select Name from Dropdown\" width=\"582\" height=\"288\" aria-describedby=\"caption-attachment-7929\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7929\" class=\"wp-caption-text\">Select Name from Dropdown<\/p>\n<\/div>\n<div id=\"attachment_7930\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-dropdown-2.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7930\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/07\/gtkdialog-dropdown-2.jpeg\" alt=\"Select Number from Dropdown\" width=\"615\" height=\"333\" aria-describedby=\"caption-attachment-7930\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7930\" class=\"wp-caption-text\">Select Number from Dropdown<\/p>\n<\/div>\n<p>Here, the explanation of code in more detailed fashion.<\/p>\n<ol>\n<li>We created two notebook tabs using &lt;notebook&gt;, the tab-label option is where you can create tabs, gtkdialog will create tabs depending on the labels you enter, every &lt;vbox&gt; is defined as a tab, so the first tab starts with the first &lt;vbox&gt;, the second tab starts with the second &lt;vbox&gt;.<\/li>\n<li><b>&lt;text&gt;<\/b>\u00a0is a text widget, we used the &lt;label&gt; tag to set the default text for it.<\/li>\n<li><b>&lt;spinbutton&gt;<\/b>\u00a0tag will create a new spin button, range-min option is the minimum value, and range-max is the maximum value for the spin button, range-value is the default value for the spin button.<\/li>\n<li>We gave a variable \u201cmyscale\u201d to the &lt;spinbutton&gt;.<\/li>\n<li>We printed the selected value using echo and $myscale variable, the default signal for the action here is \u201cvalue-changed\u201d which helped us doing that.<\/li>\n<\/ol>\n<p>This was just an example window, you can create more complicated interfaces using gtkdialog if you want, you can browse the official documentation in gtkdialog website to view all gtkdialog tags from the link below.<\/p>\n<p><a href=\"https:\/\/code.google.com\/p\/gtkdialog\/#Documentation\" target=\"_blank\" rel=\"nofollow noopener\">Gtkdialog Documentation<\/a><\/p>\n<p>Have you used gtkdialog to create GUIs for your shell scripts before? Or have you used any such utility to create interfaces? What do you think about it?<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/gtkdialog-create-graphical-interfaces-and-dialog-boxes\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gtkdialog\u00a0(or gtkdialog) is an open source nifty utility for creating and building GTK+ Interfaces and Dialog Boxes with the help of Linux shell scripts and using GTK library, as well as using an xml-like syntax, which makes easy to create interfaces using gtkdialog. It is much similar to most famous tool called Zenity, but it &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/gtkdialog-create-graphical-gtk-interfaces-and-dialog-boxes-using-shell-scripts-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Gtkdialog \u2013 Create Graphical (GTK+) Interfaces and Dialog Boxes Using Shell Scripts in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12435","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12435"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12435\/revisions"}],"predecessor-version":[{"id":12436,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12435\/revisions\/12436"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}