Custom GUI with few lines like AutoHotkey
In AutoHotkey (Windows-only scripting tool), it is possible to create thorough graphical user interfaces with very few lines of code. You create a GUI and add or edit its elements. Any element can have a listener installed just using the option g-label
.
Consider this interface:
For better understanding, here’s the entire AHK source code.
gui, color, BADEFA
gui, font, s6 cRed, Verdana
gui, add, text, x150 y5, Hello!
gui, font
gui, add, text, x10 y5, This is a gui.
gui, add, dropDownList, w60 gcolor_selected vselected_color, Black|White|Green||Blue
gui, add, text, xp+70 yp+0 vcolor_prompt w120
gui, add, picture, x10, kitten.png
gui, show, center w300, I am a beatiful GUI
return
color_selected:
gui, submit, nohide
guicontrol,, color_prompt, You selected %selected_color%
gui, font, c%selected_color%
guicontrol, font, color_prompt
return
The above screenshot was made using WINE. I am looking for a language, tool, script which offers similar GUI-functionality like AHK does for Windows, mostly in terms of simplicity. The absolute coordinate syntax (option x[X] y[Y]
) is the central requirement. The best I could come up with so far is Python’s TkInter, which doesn’t even support absolute positioning. Is this the most compact solution there is for Ubuntu?
Edit 5 years later: Instead of the below, I’d now suggest my other project for this, AHK_X11, AutoHotkey for Linux. Several things are still missing, but the above script should work mostly fine.
Could not find any, so I did one myself. Tcl/Tk is the closest I could find, however it is (as the name suggests) Tcl
code.
So, it is called TkBash and is a bash wrapper around the tcl code. Here is my attempt to recreate the image from the question:
#!/bin/bash
tkbash 1 window --theme clam --w 290 -h 200
tkbash 1 --tkcommand ". configure -background lightblue"
tkbash 1 label label1 -x 10 -y 10 -w 80 -h 20 -t "This is a gui."
tkbash 1 label label2 -x 140 -y 10 -w 30 -h 15 -t "Hello!"
tkbash 1 --tkcommand "font create myfont -family Helvetica -size 8"
tkbash 1 label2 --tkcommand "configure -font myfont"
tkbash 1 select select1 -x 10 -y 30 -w 80 -h 20 -t "Black|White|Green||Blue"
tkbash 1 label label3 -x 95 -y 30 -w 120 -h 20
tkbash 1 button button1 -x 245 -y 25 -w 30 -h 30 -t "ok" -c "
selected_color="$(tkbash 1 get select1)"
tkbash 1 label3 -t "You selected $selected_color""
tkbash 1 image image1 -x 10 -y 60 -w 125 -h 120 --image "kitten.png"