Going Graphical — The dialog Utility

本文详细介绍了多种对话框类型及其创建所需的参数,包括复选框、信息框、输入框等,并通过具体示例展示了如何使用这些对话框进行简单的用户交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

dialog --msgbox “Hello World” 9 18

dialog

The principal types of dialogs you can create are described in the following table:

TypeOption Used to Create TypeMeaning
Check boxes–checklistAllows you to display a list of items, each of which may be individually selected
Info boxes–infoboxA simple display in a box that returns immediately, without clearing the screen
Input boxes–inputboxAllows the user to type in text
Menu boxes–menuAllow the user to pick a single item from a list
Message boxes–msgboxDisplays a message to users, with an OK button when they wish to continue
Radio selection boxes–radiolistAllows the user to select an option from a list
Text boxes–textboxAllows you to display a file in a scroll-ing box
Yes/No boxes–yesnoAllows you to ask a question, to which the user can select either yes or no

We list the different parameters required for each type in the following table:

Dialog TypeParameters
–checklisttext height width list-height [tag text status] …
–infoboxtext height width
–inputboxtext height width [initial string]
–menutext height width menu-height [tag item ] …
–msgboxtext height width
–radiolisttext height width list-height [tag text status] …
–textboxfilename height width
–yesnotext height width

//
In this example, you create a checklist-type box, with a title Check me and the instructions Pick Numbers . The checklist box will be 15 characters high by 25 characters wide, and each option will occupy 3 characters of height. Last, but not least, you list the options to be displayed, along with a default on/off selection.

xxx@xxx-pc ~ $ dialog --title "Check me" --checklist "Pick Numbers" 15 25 3 1 "one" "off" 2 "two" "on" 3 "three" "off"c

checkme

The options look a little tricky, but all you have to remember is that each menu item has three values:
❑ Bullet number
❑ Text
❑ Status

check the environment variable $? , which you will recall is the exit status of the previous command.

all dialog type :
–title , which allows you to specify a title for the box,
–clear , which is used on its own for clearing the screen.

small gui from shell .GNOME can use gdialog .

#!/bin/sh

# Ask some questions and collect the answer

gdialog --title "Questionnaire" --msgbox "Welcome to my simple survey" 9 18

gdialog --title "Confirm" --yesno "Are you willing to take part?" 9 18
if [ $? != 0 ]; then
    gdialog --infobox "Thank you anyway" 5 20
    sleep 2
    gdialog --clear
    exit 0
fi

gdialog --title "Questionnaire" --inputbox "Please enter your name" 9 30 2>_1.txt
Q_NAME=$(cat _1.txt)

gdialog --menu "$Q_NAME, what music do you like best?" 15 30 4 1 "Classical" 2 "Jazz" 3 "Country" 4 "Other" 2>_1.txt
Q_MUSIC=$(cat _1.txt)

if [ "$Q_MUSIC" = "1" ]; then
    gdialog --title "Likes Classical" --msgbox "Good choice!" 12 25
else
    gdialog --title "Doesn't like Classical" --msgbox "Shame" 12 25
fi

sleep 2
gdialog --clear
exit 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值