【问题标题】:Two entry boxes on one zenity command一个 zenity 命令上的两个输入框
【发布时间】:2015-03-19 20:36:28
【问题描述】:

使用 zenity 我可以创建一个这样的组合框

zenity --entry --title "Window title" --text "Insert your choice." a b c d e

如何在一个对话框中创建两个组合框,我尝试使用这样的分隔符命令

zenity --entry --title "Select Flash Drives" --text "Insert your choice." --separator="," --add-entry="IP address" --add-entry="PORT"

但它说

--separator is not supported for this dialog

是否可以在一个 Zenity 对话框中创建两个组合框

【问题讨论】:

    标签: ubuntu-14.04 zenity


    【解决方案1】:

    虽然两个组合框是不可能的,但使用--forms 选项可以在一个对话框中生成两个输入框,它还允许合并列表(用户最多可以从每个列表中选择一个项目):

    zenity --forms --title "Select Flash Drives" --text  "Select Flash Drives" \
    --add-entry "Insert your choice" \
    --add-entry="IP address"
    

    甚至

    zenity --forms --title "Select Flash Drives" --text  "Select Flash Drives" \
    --add-list "Insert your choice" --list-values 'a|b|c' \
    --add-entry="IP address" --add-entry="PORT"
    

    --forms 的主要问题是它不允许使用默认值。 (除非表单以列表开头,在这种情况下,默认情况下似乎选择了它的第一个值。)唯一的解决方法是在问题文本中指定默认值(以便用户看到它),然后检查用户是否在 zenity 之外的脚本中提供了任何值:

    RETURNVALUE=`zenity --forms --title "Select Flash Drives" --text  "Select Flash Drives" \
    --add-entry="IP address (leave empty to use 8.8.8.8)" \
    --add-list "Insert your choice (leave empty to use C)" --list-values 'a|b|c'`
    
    # extract the IP and DRIVE values
    IP=$(awk -F'|' '{print $1}' <<<$RETURNVALUE);    
    DRIVE=$(awk -F'|' '{print $2}' <<<$RETURNVALUE);
    
    # [[ -z $var ]] is true iff the length of $var is zero
    # the second element in && is evaluated only if the first one is true 
    [[ -z $IP ]] && IP="8.8.8.8";                    
    [[ -z $DRIVE ]] && DRIVE="C";
    

    【讨论】:

      【解决方案2】:

      ,这是不可能的。 Zenity 旨在“创建简单的对话”,而您所要求的就是离 simple 更进一步。

      我认为您需要寻找不同的工具。 YAD 是 Zenity 的一个分支,它增加了一些改进,可能会帮助你实现你想要的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多