7

I want to crate a GUI for some command line programs and I need to get info from multiple text fields e.g. 'Username', 'Password' and a checkbox 'Sign automatically?'.

I need to set particular variables in my script equal to the respective text fields' input by the user e.g. user, pass, login. Also it would have an OK button and a Quit button.

How can I realise this this? I searched online and I was able to find only examples with one text field?

Zelda
  • 6,158
  • 1
  • 21
  • 27
Ufoguy
  • 1,210
  • 3
  • 13
  • 21

3 Answers3

10

Basically, you can use multi-entry forms using Zenity. A form can be built using text fields, password fields, and calendars. Text fields can be added with the --add-entry flag. Password fields are added with the --add-password flag, and calandars are added with the --add-calendar flag.

 $ zenity --forms --title="Create user" --text="Add new user" \
   --add-entry="First Name" \
   --add-entry="Last Name" \
   --add-entry="Username" \
   --add-password="Password" \
   --add-password="Confirm Password" \
   --add-calendar="Expires"

Zenity form

Here is a tutorial that might help you out.

symcbean
  • 5,008
  • 2
  • 25
  • 37
Jhondoe
  • 361
  • 1
  • 3
  • 12
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – HalosGhost Jan 14 '15 at 20:19
  • 1
    Is that better @HalosGhost and if so then can you up vote – Jhondoe Jan 14 '15 at 20:31
  • This looks *much* better. However, if you got the idea from the page you linked to originally, you should still include the link as a source reference. – HalosGhost Jan 14 '15 at 21:04
  • I no longer have the link@HalosGhost – Jhondoe Jan 14 '15 at 21:06
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/20254/discussion-between-halosghost-and-jhondoe). – HalosGhost Jan 14 '15 at 21:09
  • the output of the fields values is quite simple, a string separated by '|', sequentially related to the fields order; I came here looking for the meaning of "--forms", zenity is really useful for the majority of simple (and even not that simple) GUI requirements. From what I read, [yad](http://www.webupd8.org/2010/12/yad-zenity-on-steroids-display.html) can do even more, but not that many ppl seem to have it, but is simple to add the repository too. – Aquarius Power Nov 29 '15 at 05:30
2

I do not believe you can do this using Zenity. It's meant for simple GUI's and isn't really a full fledged GUI environment. You'll either have to change the flow of your tool or use GTK+ directly to get your desired results.

slm
  • 363,520
  • 117
  • 767
  • 871
  • 1
    do you believe the extra functionalities of [yad](http://www.webupd8.org/2010/12/yad-zenity-on-steroids-display.html) could suffice? as the questioner stated, it is for command line programs, and so, that extra complexity is certainly not required. – Aquarius Power Nov 29 '15 at 05:35
0

Try this:

yad --form \
    --field User "" \
    --field Password:H "" \
    --field "Sign Automatically?":CHK FALSE
  • the question have "using zenity" – Sérgio May 30 '21 at 02:50
  • YAD is a superb zenity fork. Can you solve this question using zenity? Is there a way to put a checkbox on the zenity form? Of course not, but how you can see is very simple to do it using YAD. And that’s why YAD is called zenity on steroids – user3043023 May 31 '21 at 12:32