How to show a GUI message box from a bash script in linux?

前端 未结 13 2194
孤街浪徒
孤街浪徒 2020-12-04 04:58

I\'m writing a few little bash scripts under Ubuntu linux. I want to be able to run them from the GUI without needing a terminal window to enter any input or view any output

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 05:42

    The zenity application appears to be what you are looking for.

    To take input from zenity, you can specify a variable and have the output of zenity --entry saved to it. It looks something like this:

    my_variable=$(zenity --entry)
    

    If you look at the value in my_variable now, it will be whatever was typed in the zenity pop up entry dialog.

    If you want to give some sort of prompt as to what the user (or you) should enter in the dialog, add the --text switch with the label that you want. It looks something like this:

    my_variable=$(zenity --entry --text="What's my variable:")
    

    Zenity has lot of other nice options that are for specific tasks, so you might want to check those out as well with zenity --help. One example is the --calendar option that let's you select a date from a graphical calendar.

    my_date=$(zenity --calendar)
    

    Which gives a nicely formatted date based on what the user clicked on:

    echo ${my_date}
    

    gives:

    08/05/2009

    There are also options for slider selectors, errors, lists and so on.

    Hope this helps.

提交回复
热议问题