3

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"
Remi.b
  • 17,389
  • 28
  • 87
  • 168

3 Answers3

7

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.

Nexus
  • 106
  • 1
  • 3
4

--question is what you are looking for:

zenity --question \
--title="" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"
tmt
  • 7,611
  • 4
  • 32
  • 46
-1

you can also use --info

zenity --info \
--title="A or B" \
--text "Choose A or B" \
--ok-label="B" \
--cancel-label="A"
Matthew Verstraete
  • 6,335
  • 22
  • 67
  • 123
dharmi_kid
  • 19
  • 4