2008-01-03

ttk::progressbar


回は Ttk の話題に戻り、ttk::progressbar を紹介します。このウィジェットは、時間が掛かる処理の進捗具合を表示するウィジェットです。



#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"


# ----------------------------------------------------------------------------
# dummy work
# ----------------------------------------------------------------------------

proc dummyStart {varName} {
upvar #0 $varName x; # widget variable has gloval scope
for {set i 1} {$i <= 100} {incr i} {
set x $i
update
after 100
}
}

# ----------------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------------

wm title . "ttk::progressbar"
ttk::style theme use "clam"

ttk::progressbar .p1 -length 200 -variable p -mode determinate
ttk::progressbar .p2 -length 200 -variable p -mode indeterminate
ttk::button .start -text "START" -command {dummyStart "p"}

grid .p1 -pady 5 -padx 10
grid .p2 -pady 5 -padx 10
grid .start -padx 10 -pady 5 -sticky news
grid columnconfigure . all -weight 1

# ---
# ttkwidget_progressbar.tcl


拡張パッケージ Incr Widgets の feedback ウィジェットでも同じような機能を実現できます。以下に簡単な例を示しました。



#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"


package require Iwidgets

# ----------------------------------------------------------------------------
# dummy work
# ----------------------------------------------------------------------------

proc dummyStart {w} {
$w reset
for {set i 0} {$i < 100} {incr i} {
$w step
after 100
}
}

# ----------------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------------

wm title . "iwidgets::feedback"

iwidgets::feedback .fb \
-labeltext " percentage of completion " \
-steps 100 \
-barheight 10

button .start -text "START" \
-command {dummyStart .fb}

pack .fb -padx 4 -pady 4
pack .start -padx 4 -pady 4
# ---
# iwidgets_feedback.tcl

0 件のコメント: