【问题标题】:How do you create an interactive menu in scheme如何在方案中创建交互式菜单
【发布时间】:2016-12-26 15:40:50
【问题描述】:

我最近接到了创建一个需要使用菜单的程序的任务。但是,我不知道如何创建一个窗口并使其显示可以使用某个键进行交互的文本,比如说“输入”键。有人对如何做到这一点有任何提示吗?

【问题讨论】:

    标签: user-interface menu scheme user-interaction


    【解决方案1】:

    方案报告不支持 GUI,因此唯一可移植的是 CLI 界面。这是一个非常简单的程序,只有这些部分。

    #!r6rs
    (import (rnrs))
    
    (define *stdin* (current-input-port))
    (define (readline)
      (get-line *stdin*))
    
    ;;; displays a textual menu
    (define (menu)
      (display "Menu\n1. read input\n2. print data\n3. empty input\n"))
    
    ;; read until we got the value between 1 and 3 from user
    (define (read-command)
      (display "Enter choice [1-3] >")
      (let* ((in (readline))
             (n (string->number in)))
        (cond ((<= 1 n 3) n)
              (else
               (display "Invalid choice \"")
               (display in)
               (display "\"\n")
               (read-command)))))
    
    
    (define (driver data)
      (menu)
      (let ((choice (read-command)))
        (cond ((= choice 1) (display "Enter text >")
                            (driver (cons (readline) data)))
              ((= choice 2) (display "Data:\n")
                            (display data)
                            (newline)
                            (driver data))
              (else (display "Emptied\n")
                    (driver '())))))
    
    (driver '())
    

    当然,个别实现具有 GUI 支持。例如。 Racket 有一种方法可以创建桌面应用程序,其中菜单可以是您单击的按钮。

    【讨论】:

      猜你喜欢
      • 2018-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2019-09-20
      • 2020-05-06
      相关资源
      最近更新 更多