Trying out Tk GUIs in CL
A noob trying out Tk GUIs in Common Lisp.
Nothing fancy, private tests, hopefully helping someone to getting
started, until they make it to a proper tutorial.
NEW! Peter Lane assembled an excellent resource for Ltk and Nodgui:
NEW! nodgui supports custom Tk themes!! See gallery below.
To test:
git clone https://github.com/TkinterEP/ttkthemes/
at this project’s root (or use the “yaru” theme, commited).
How to create widgets: (make-instance 'widget-name)
, for example
(make-instance 'frame)
(make-instance 'treeview)
How to place them on the grid:
;; (grid <widget> <column> <row> &options)
(grid c 0 0 :sticky "n" ;; north
:padx 5 :pady 5)
The rest is discoverable !
With nodgui, yaru and breeze theme (more below):
https://gist.github.com/jasom/4c4bf02e60d85f2644f99ce7be5dce17
(make-instance 'treeview)
;; and
(treeview-insert c.tree :text "some text"))
With columns:
(commented sources)
A simple example:
;; Always use with-nodgui or with-ltk.
(with-nodgui ()
(let ((tree (make-instance 'scrolled-treeview
;; a treeview always has a first column.
:columns (list "col2"))))
;; We place our widget on the grid to see it.
(grid tree 1 0)
(loop for data in '("aaa" "bbb" "ccc")
do (treeview-insert-item tree
;; text of the first column.
:text data
;; text of the other columns.
:column-values (list "val2")))))
For collapsable rows, the use of parents
and children
, an example: https://notabug.org/cage/nodgui/src/7e6da313d99d4b260aadab595fe4b0f843520da7/src/demo-tests.lisp
Another example showing a treeview, with columns, inserting content
from a searchbox, clearing the tree’s content, and others (resizing,
etc): see example-treeview-search-display
.
Using Peter Lane’s listbox example: https://peterlane.codeberg.page/ltk-examples/#_more_widgets
We display a list of strings (file names), we add a select box (select
media player), a button (listen), and we play the file with an
external program.
Might become a general utility in my growing scripts: send a list of something, decide of the action, do it.
See musicplayer-nodgui.lisp.
We can use Tk themes, that’s huge!
I cloned ttkthemes (gallery) locally.
We need to eval a tcl file, and set the theme:
;; inside nodgui:with-nodgui main loop.
(eval-tcl-file "ttkthemes/ttkthemes/png/yaru/yaru.tcl")
(use-theme "yaru")
and that’s it.
The awthemes are supposed to be supported (didn’t try yet).
List of Tcl/Tk themes: https://wiki.tcl-lang.org/page/List+of+ttk+Themes
The gif themes of ttkthemes are not yet supported, but will be when tklib
lands in Debian. Read nodgui #13.
note: the “scid” and “smog” themes bugged.
Screenshot from its readme:
(by the same author, Azure and Sun Valley themes didn’t load)
http://www.peter-herth.de/ltk/ltkdoc/node8.html
run (start-wish)
and start building interactively !
(defparameter *button* (make-instance 'button :text "OK"))
(grid *button* 1 0 :sticky "e")
and voilà, you didn’t have to restart the main loop to see the new
button into the interface.
We didn’t have to use the with-ltk
macro too.
Then (exit-wish)
.
The nodgui demo shows a lot of widgets:
Try it out with
(ql:quickload :nodgui)
(nodgui.demo:demo)
Tk tutorials used: