项目作者: vindarel

项目描述 :
Trying out Tk GUIs in CL
高级语言: Common Lisp
项目地址: git://github.com/vindarel/ltk-tests.git
创建时间: 2019-02-15T17:53:37Z
项目社区:https://github.com/vindarel/ltk-tests

开源协议:

下载


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:

  1. git clone https://github.com/TkinterEP/ttkthemes/

at this project’s root (or use the “yaru” theme, commited).

Quick Insights

How to create widgets: (make-instance 'widget-name), for example

  1. (make-instance 'frame)
  2. (make-instance 'treeview)

How to place them on the grid:

  1. ;; (grid <widget> <column> <row> &options)
  2. (grid c 0 0 :sticky "n" ;; north
  3. :padx 5 :pady 5)

The rest is discoverable !

With nodgui, yaru and breeze theme (more below):

https://gist.github.com/jasom/4c4bf02e60d85f2644f99ce7be5dce17

Tree widget

  1. (make-instance 'treeview)
  2. ;; and
  3. (treeview-insert c.tree :text "some text"))

With columns:

(commented sources)

A simple example:

  1. ;; Always use with-nodgui or with-ltk.
  2. (with-nodgui ()
  3. (let ((tree (make-instance 'scrolled-treeview
  4. ;; a treeview always has a first column.
  5. :columns (list "col2"))))
  6. ;; We place our widget on the grid to see it.
  7. (grid tree 1 0)
  8. (loop for data in '("aaa" "bbb" "ccc")
  9. do (treeview-insert-item tree
  10. ;; text of the first column.
  11. :text data
  12. ;; text of the other columns.
  13. :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.

Media player

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.

Media player (nodgui, themes)

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:

  1. ;; inside nodgui:with-nodgui main loop.
  2. (eval-tcl-file "ttkthemes/ttkthemes/png/yaru/yaru.tcl")
  3. (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.

More themes

Forest theme

Screenshot from its readme:

(by the same author, Azure and Sun Valley themes didn’t load)

Ale themes

Interactively building the GUI

http://www.peter-herth.de/ltk/ltkdoc/node8.html

run (start-wish) and start building interactively !

  1. (defparameter *button* (make-instance 'button :text "OK"))
  2. (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).

Demo

The nodgui demo shows a lot of widgets:

Try it out with

  1. (ql:quickload :nodgui)
  2. (nodgui.demo:demo)

Links

Tk tutorials used:

Example apps