Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zenity dialog window with two buttons but no text entry

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"
like image 619
Remi.b Avatar asked Sep 07 '25 12:09

Remi.b


2 Answers

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.

like image 76
Nexus Avatar answered Sep 10 '25 06:09

Nexus


--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)

like image 39
tmt Avatar answered Sep 10 '25 07:09

tmt