gtk.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (use-modules (gi) (gi repository))
  2. (require "Gio" "2.0")
  3. (require "Gtk" "3.0")
  4. (load-by-name "Gio" "Application") ;; activate, run
  5. (load-by-name "Gtk" "Application")
  6. (load-by-name "Gtk" "ApplicationWindow")
  7. (load-by-name "Gtk" "Button")
  8. (load-by-name "Gtk" "ButtonBox")
  9. (load-by-name "Gtk" "Widget") ;; show-all
  10. (define (print-hello widget)
  11. (display "Hello World\n"))
  12. (define (activate-callback app)
  13. (let* ((window (make <GtkApplicationWindow>
  14. #:application app
  15. #:default-height 200
  16. #:default-width 200
  17. #:title "Window"))
  18. (button-box (make <GtkButtonBox> #:parent window))
  19. (button (make <GtkButton>
  20. #:parent button-box
  21. #:label "Hello world")))
  22. (connect button clicked print-hello)
  23. (connect button clicked (lambda _ (destroy window)))
  24. (show-all window)))
  25. (define (main)
  26. (let ((app (make <GtkApplication> #:application-id "org.gtk.example")))
  27. (connect app activate activate-callback)
  28. (run app (command-line))))
  29. (main)