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"
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.
--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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With