Linux使用whiptail形成对话框的方法-游戏攻略-霍普软件下载网

网站首页   软件下载   游戏下载   翻译软件   电子书下载   电影下载   电视剧下载   教程攻略   音乐专区

请输入您要查询的教程攻略:

霍普软件下载网-旗舰软件下载站,将绿色免费商业版破解软件、共享软件、游戏、电影、电视剧一网打尽!

文章 Linux使用whiptail形成对话框的方法
分类 教程攻略
语言 zh-CN
大小
版本
下载 暂无下载
介绍     
    在Linux中可以使用命令来形成对话框,Linux命令行形成的对话框就是以代码的形式出现。whiptail就是一个Linux可以形成对话框的命令行,本文就来介绍一下Linux使用whiptail形成对话框的方法。
    Linux使用whiptail形成对话框的方法
    分享一个写好的东西。
    #!/bin/bash
    trap “” 2
    while true
    do
    OPTION=$(whiptail --title “Email Manager” --nocancel --menu “Choose your option” 15 60 4 \\
    “1” “Add Email User” \\
    “2” “Delete Email User” \\
    “3” “List Email User” \\
    “4” “EXIT” 3》&1 1》&2 2》&3)
    case $OPTION in
    1)
    EmailAddress=$(whiptail --title “EmailAddress-form Input Box” --inputbox “What is your add EmailAddress?” 10 60 @shenxu.com 3》&1 1》&2 2》&3)
    15. 人世间有百媚千红,唯独你是我情之所钟。  exitstatus=$?
    if [ $exitstatus = 0 ]; then
    grep $EmailAddress /etc/postfix/virtual_mailbox_maps》/dev/nul
    exitstatus=$?
    if [ $exitstatus = 0 ]; then
    whiptail --msgbox “The Email Address is a existed” 10 40
    elif (whiptail --title “Add Yes/No Box” --yesno “Are you sure add $EmailAddress.” 10 60) then
    /etc/postfix/mailadd.sh $EmailAddress
    whiptail --msgbox “The Email Address $EmailAddress is a added.” 10 40
    fi
    else
    whiptail --msgbox “You chose Cancel.” 10 40
    fi
    ;;
    2)
    EmailAddress=$(whiptail --title “EmailAddress-form Input Box” --inputbox “What is your Delete EmailAddress?” 10 60 @shenxu.com 3》&1 1》&2 2》&3)
    exitstatus=$?
    if [ $exitstatus = 0 ]; then
    grep $EmailAddress /etc/postfix/virtual_mailbox_maps》/dev/nul
    exitstatus=$?
    if [ $exitstatus != 0 ]; then
    whiptail --msgbox “The Email Address $EmailAddress is a not exist.” 10 40
    elif (whiptail --title “Add Yes/No Box” --yesno “Are you sure delete $EmailAddress.” 10 60) then
    /etc/postfix/maildel.sh $EmailAddress
    whiptail --msgbox “The Email Address $EmailAddress is a deleted.” 10 40
    fi
    else
    whiptail --msgbox “You chose Cancel.” 10 40
    fi
    ;;
    3)
    EmailAddress=$(cat /etc/postfix/virtual_mailbox_maps | awk ‘{print $1}’)
    whiptail --msgbox “The Email User list are $EmailAddress.” --scrolltext 20 40
    ;;
    4)
    echo “EXIT”
    break
    ;;
    esac
    done
    trap : 2
    whiptail --title “Email Manager” --nocancel --menu “Choose your option” 15 60 4 \\
    “1” “Add Email User” \\
    “2” “Delete Email User” \\
    “3” “List Email User” \\
    “4” “EXIT” 3》&1 1》&2 2》&3
    --title “Email Manager” 是标题,双引号里是自己填的提示信息
    --nocancel 是在这个图文里面不显示取消,只显示OK
    --menu “Choose your option” 15 60 4 是表示菜单提示,双引号里是自己填的提示信息,15是高度,60是长度,4是有个选择项目
    下面的1-4是自己的提示
    最后比较关键,3》&1 1》&2 2》&3是为了把选择的内容填进变量OPTION
    whiptail --title “EmailAddress-form Input Box” --inputbox “What is your add EmailAddress?” 10 60 @shenxu.com 3》&1 1》&2 2》&3
    --inputbox “What is your add EmailAddress?” 是可以形成一个让用户输入的提示框
    @shenxu.com 是默认输入text里的值
    whiptail --msgbox “You chose Cancel.” 10 40 是显示一行你的提示
    其实还有--infobox,似乎和msgbox很像,其实不同,它基本上用不上,是在shell运行完后,可以往前翻页能看见的东西
    --scrolltext 20 40是为了显示多行的时候可以上下滚动
    另外还有--passwordbox和text一样输入,就是以***显示
    whiptail --checklist “choose” 15 60 2 “1” “aa” ON “2” “bb” ON
    15 60还是高和宽,2是有几个选项,和menu一样,后面多了一个ON或者OFF表示状态,就是菜单出来后默认是不是选,On是选,OFF不选,用空格键来选择。可以多选。
    --radiolist,不可以多选了。ON就只能有一个,其它必须是OFF
    还有一个显示进度条的--gauge,我觉得没啥用处。
    #!/bin/bash
    {
    for n in `seq 100`
    do
    sleep 1
    echo $n
    done
    } | whiptail --gauge “Please wait while installing” 6 60 0
    以上就是Linux使用whiptail形成对话框的方法,把写好的代码复制到whiptail里面就可以形成对话框了。
    
截图
随便看

免责声明
本网站所展示的内容均来源于互联网,本站自身不存储、不制作、不上传任何内容,仅对网络上已公开的信息进行整理与展示。
本站不对所转载内容的真实性、完整性和合法性负责,所有内容仅供学习与参考使用。
若您认为本站展示的内容可能存在侵权或违规情形,请您提供相关权属证明与联系方式,我们将在收到有效通知后第一时间予以删除或屏蔽。
本网站对因使用或依赖本站信息所造成的任何直接或间接损失概不承担责任。联系邮箱:101bt@pm.me