Reputation: 18219
I would like to create a zenity dialog window with two buttons as only user input.
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"
Upvotes: 4
Views: 16348
Reputation: 1
Interesting, the --extra-button thing and the --switch thing...
Button-processing can maybe be confusing to some of us sometimes with zenity. By default, when you leave out the OK and Cancel button, every extra button gets assigned the same '$?'.
Maybe a for-loop is more logical than a while-loop?
Solely reacting upon each button text (important to avoid spatial problems by double quoting!).
At least sth like this appears to give good clear button action results:
ZEN=$(zenity --question --title "Zen Window" --text "How Zen Are You?" --switch --extra-button "Very Zen" --extra-button "Modestly Zen" --extra-button "Not Zen at All")
for z in "${ZEN}"
do
if [[ "${z}" == "Very Zen" ]]
then
echo "Very Zen."
elif [[ "${z}" == "Modestly Zen" ]]
then
echo "Modestly Zen."
elif [[ "${z}" == "Not Zen at All" ]]
then
echo "Not Zen at All."
fi
done
Upvotes: 0
Reputation: 8614
--question
is what you are looking for:
zenity --question \
--title="" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"
You may also try:
zenity --question \
--text="Choose A or B" \
--switch \
--extra-button "A" \
--extra-button "B"
This automatically generates a dialog with just your two extra buttons. (--switch
suppresses the default OK and Cancel buttons)
Upvotes: 5
Reputation: 180
At least recent versions of zenity have an --extra-button flag.
Combining the value of the exit code and the content of stdout, the code can figure out what the user did.
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.
Upvotes: 10
Reputation: 19
you can also use --info
zenity --info \
--title="A or B" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"
Upvotes: -1