Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 8779  / 1 Year ago, thu, february 9, 2023, 1:07:07

I found by chance it was possible to display a combo box with zenity (version tested: 2.32.1). See the following code:



#!/bin/bash
array=(a b c d e)
value=$(zenity --entry --title "Window title" --text "${array[@]}" --text "Insert your choice.")


The result is illustrated with the following 3 images:



enter image description here



enter image description here



enter image description here



I have two questions about that:




  1. Is there a documentation about this functionality? I didn't find anything in the zenity documentation.


  2. Why the first value of my array doesn't appear in the combo box? In the example above, my array is (a b c d e), and the combo box only displays b c d e.



    As a workaround, I add a value in my array, for example (0 a b c d e).



More From » zenity

 Answers
1

The first element of the array gets eaten up by --text. After expansion, your zenitiy line looks like:





zenity --entry --title "Window title" --text a b c d e --text "Insert your choice."
# Which zenity treats equivalent to
zenity --entry --title "Window title" --text a --text "Insert your choice." b c d e


So you first set the text to a, then you override that with "Insert your choice." And the remaining arguments become the choices.



What you want is:



zenity --entry --title "Window title" --text "Insert your choice." a b c d e
# Hence:
zenity --entry --title "Window title" --text "Insert your choice." "${array[@]}"

[#44413] Friday, February 10, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
urnaetted

Total Points: 10
Total Questions: 113
Total Answers: 117

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
urnaetted questions
;