例如:创建一个弹窗,获取所有的组件将其在列表控件中显示,效果如下。
源码:test.tcl
proc myDialog {{dialogTitle "dialog"}} {
*clearmarkall 1
catch {destroy .dialog}
toplevel .dialog;
wm withdraw .dialog;
frame .dialog.frame -relief flat;
pack .dialog.frame -fill both -expand true;
set listname [listbox .dialog.frame.listbox]; # 创建列表控件
set compNameList [list]
catch {set compNameList [hm_complist name]} # 获取当前项目中的所有组件名称
foreach compName $compNameList {
$listname insert end $compName;
}
pack $listname -fill both -expand true;
# 设置窗口显示样式
wm title .dialog $dialogTitle;
wm minsize .dialog 400 300;
wm maxsize .dialog 400 300;
wm protocol .dialog WM_DELETE_WINDOW {destroy .dialog};
wm transient .dialog;
wm deiconify .dialog;
wm attributes .dialog -topmost false
set x [expr {[winfo screenwidth .]-[winfo width .]/2}]
# 主窗口大小
set y [expr {([winfo screenheight .]-[winfo height .])/2}]
# 主窗口大小
wm geometry . 400x300+$x+$y
}
调用方式:myDialog "hello"