bash 带有两个按钮但没有文本输入的 Zenity 对话框窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37997249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
zenity dialog window with two buttons but no text entry
提问by Remi.b
I would like to create a zenity dialog window with two buttons as only user input.
我想创建一个带有两个按钮的 zenity 对话框窗口,仅作为用户输入。
The following creates a window with two buttons but with a space for a text entry
下面创建一个带有两个按钮的窗口,但有一个文本输入空间
zenity --entry --title="" --text "Choose A or B" --ok-label="B" --cancel-label="A"
The following creates a window with one button only
下面创建一个只有一个按钮的窗口
zenity --info --title="" --text "Choose A or B" --ok-label="B"
回答by tmt
--question
is what you are looking for:
--question
是你要找的:
zenity --question \
--title="" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"
回答by Nexus
At least recent versions of zenity have an --extra-button flag.
至少最新版本的 zenity 有一个 --extra-button 标志。
Combining the value of the exit code and the content of stdout, the code can figure out what the user did.
结合退出代码的值和stdout的内容,代码可以弄清楚用户做了什么。
For example:
例如:
while true; do
ans=$(zenity --info --title 'Choose!' \
--text 'Choose A or B or C' \
--ok-label A \
--extra-button B --extra-button C \
--timeout 3)
rc=$?
echo "${rc}-${ans}"
done
Results would look like this:
结果如下所示:
# timeout
5-
# ESC key
1-
# A button
0-
# B button
1-B
# C button
1-C
Note that the above works similarly other dialogs, though certain combinations may be surprising. Be sure to experiment and handle all sorts of different user interactions.
请注意,上述内容与其他对话框的工作方式类似,但某些组合可能会令人惊讶。一定要试验和处理各种不同的用户交互。
回答by dharmi_kid
you can also use --info
你也可以使用 --info
zenity --info \
--title="A or B" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"