0

使用 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 对话框中创建两个组合框

4

2 回答 2

4

虽然不可能有两个组合框,但可以使用该--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";
于 2015-11-03T18:47:19.493 回答
2

No, it's not possible. Zenity is designed "to create simple dialogs" and what you are asking for is that one tiny step further from simple.

I think you need to look for a different tool. YAD is a fork of Zenity that adds some improvements and might help you achieve what you want.

于 2015-03-23T12:01:44.147 回答