A complete zenity dialog examples

本文详细介绍Zenity工具的各种对话框使用方法,包括日历、输入框、错误提示等,并提供实际示例代码。

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

A complete zenity dialog examples

Zenity is a tool that help you to create a common functional GTK+
dialogs. It have various dialogs that each of them have different ways
of presenting data and acquire data from user input.
We have introduce how to make use of GUI dialog box in
Using GUI dialog box
,
where we give an example of how zenity create a question dialog box.
Besides question dialog box, zenity can create more than that, such as
calendar, entry, error, info, file selection, list, notification,
progress, warning, scale and text info. In this tutorial, we would like
to illustrate how to create every single zenity dialog by examples.
How to create zenity calendar dialog?
You are allow to specify the initial selection of date in calendar
dialog, specified with options ?day ?month ?year. The default selection
will be today’s date. Zenity will returns the date selected by user.
szDate=$(zenity --calendar --text "Pick a day" --title "Medical Leave" --day 23 --month 5
--year 2008); echo $szDate

calendar

 

How to create zenity entry dialog?
Entry dialog usually use to acquire string entry from user.
szAnswer=$(zenity --entry --text "where are you?" --entry-text "at home"); echo $szAnswer

entry

 

How to create zenity error dialog?
Create an error dialog is straight forward, it does not wait for user input.
zenity --error --text "Installation failed! "

 

error

 

How to create zenity info dialog?
zenity --info --text "Join us at irc.freenode.net #lbe."

info

 

How to create zenity File Selection dialog?
File selection dialog is one of the a very useful zenity dialog, it
support open file or save file dialog. The best part is, zenity file
selection dialog is not difficult to use. Let me show you how to create
a save file dialog box, if filename already exists, it will ask for
confirmation.
szSavePath=$(zenity --file-selection --save --confirm-overwrite);echo $szSavePath

file-selection

 

Check out more and try to create an open file dialog yourself?
zenity --help-file-selection


How to create zenity notification dialog?
To notify users regarding to some status, you can use notification dialog, a tiny icon will be appear at taskbar.
zenity  --notification  --window-icon=update.png  --text "Please update your system."
Next coming up tutorial will covers zenity dialog such as progress, question, warning, scale, text-info and list.
In this post we will covers zenity dialog for progress, question, warning, scale, text info and list.
How to create zenity progress dialog?
Progress dialog is to track a progression of a routine, it can be
anything, let say I want store the results list of open files (lsof)
into a file call lsof.txt, and uses zenity progress to track the
progression, I do this:
gksudo lsof | tee >(zenity --progress --pulsate) >lsof.txt

progress

 

I need to use tee, because without using tee, zenity will strip off my result output. Check out
tee examples
for more information.


How to create zenity question dialog?
zenity --question --text "Are you sure you want to shutdown?"; echo $?
As echo $? returns result 0 means user press yes, 1 means cancel.

question

 

How to create zenity warning dialog?
zenity --warning --text "This will kill, are you sure?";echo $?

warning

 

 

How to create zenity scale dialog?
Scale dialog allows you to set a range of number, so that user are force to pick a number within the range.
ans=$(zenity --scale --text "pick a number" --min-value=2 --max-value=100 --value=2
--step 2);echo $ans

scale

 

How to create zenity text info dialog?
Text Info can be very useful to display text out to a GUI. I use back
the lsof examples, but this time I feed the results to text info box.
gksudo lsof | zenity --text-info --width 530

text-info

 

As you can see, you can specified the width and height of a zenity
dialog. Too bad, text info dialog do not have option to disable text
wrap and specified what font to use.


How to create zenity list dialog?
List dialog is the most flexible dialog and I have spend quite
sometimes to utilize the usage. As it can generate multiple columns,
multiple selection, checklist, radiolist etc. checkout ?help-list for
more information.
This is for radiolist:
ans=$(zenity  --list  --text "Is linux.byexamples.com helpful?" --radiolist  --column "Pick"
--column "Opinion" TRUE Amazing FALSE Average FALSE "Difficult to follow" FALSE "Not helpful");
echo $ans

list

 

First you need to define a columns, then feed all the list options one by one.
This is for checklist:
ans=$(zenity  --list  --text "How linux.byexamples can be improved?" --checklist  
--column "Pick" --column "options" TRUE "More pictures" TRUE "More complete post" FALSE "
Includes Installation guidelines" FALSE "Create a forum for question queries"
--separator=":"); echo $ans

column

 

The result this time will be long and probably more than one, so you can spefify a separator to differentiate them.

 

 

源地址:

http://linux.byexamples.com/archives/259/a-complete-zenity-dialog-examples-1/

http://linux.byexamples.com/archives/265/a-complete-zenity-dialog-examples-2/

 

 

 

 

 

 

.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值