TCL/TK GUI添加组件后MainFrame尺寸参数失效求助
TCL/TK GUI主窗口尺寸设置失效问题
单独运行以下代码时,MainFrame能按-width 5000和-height 5000参数创建符合预期的大窗口:
package require BWidget MainFrame .main \ -textvariable status \ -progressvar prgindic \ -progressfg SteelBlue4 \ -progressmax 100 \ -progresstype infinite \ -width 5000 \ -height 5000 pack .main -fill both -expand 1
但为主窗口添加以下GUI元素后,MainFrame的宽高参数不再生效,窗口自动变为中等尺寸,仅能手动调整大小:
- 工具栏:
set tb [.main addtoolbar] - 按钮:
set bbox1 [ButtonBox $tb.bbox1 -spacing 0 -padx 1 -pady 1 -homogeneous 0] - Notebook组件:
set notebook [NoteBook [.main getframe].note -width 5000 -height 5000 -homogeneous 0 -tabbevelsize 4 -arcradius 3 ],并执行pack $notebook -fill both -expand 1 -side top
Notebook内部还添加了大量框架等元素,且给Notebook也设置了宽高参数,同样无法生效。
需要解答的问题:
- 是什么原因导致GUI尺寸被“覆盖”?
- TK中是否存在自动调整尺寸、忽略宽高参数的机制?
简化版可正常生效的对比代码
package require BWidget console show MainFrame .main \ -textvariable status \ -progressvar prgindic \ -progressfg SteelBlue4 \ -progressmax 100 \ -progresstype infinite \ -width 300 \ -height 300 set frame [.main getframe] puts "frame = $frame" set notebook [NoteBook $frame.note -width 300 -height 300 -homogeneous 0 -tabbevelsize 4 -arcradius 3 ] puts "notebook = $notebook" pack .main.frame pack $notebook -fill both -expand 1 -side top pack .main -fill both -expand 1 # sheet creation : set top [$notebook insert 0 test1 -text "ONGLET1"] puts "top=$top" # = .main.frame.note.ftest1 # here I can resize using : #.main.frame.note configure -width 3000 # create panedwindows in the sheet : set pw [PanedWindow $top.pw -side left -pad 4 -weights available -width 3] puts "pw=$pw" set houtil [$pw add -weight 3] puts "houtil=$houtil" # -width 3 = taille du petit cube qui permet de décaller les barres de séparation horizontales set pwhoutil [PanedWindow $houtil.pwhoutil -side top -pad 4 -weights available -width 8] puts "pwhoutil=$pwhoutil" pack $pwhoutil -fill both -expand 1 pack $pw -fill both -expand 1 # at this point I can still resize : #.main.frame.note configure -width 1000 set modules [$pwhoutil add -weight 2] set frame_def_ptr [TitleFrame $modules.frame_etape -text "Etapes de bf actif" ] pack $frame_def_ptr -side top -fill both -expand 1 # at this point I can still resize : #.main.frame.note configure -width 1000 set text [$pw add -weight 3] set notebook_log [NoteBook $text.log -width 900 -height 500 -homogeneous 1 -tabbevelsize 4 -arcradius 0 ] puts "notebook_log = $notebook_log" pack $notebook_log -fill both -expand 1 -side top # at this point I can still resize : #.main.frame.note configure -width 1000 # without effect : .main configure -width 2000 .main.frame.note.ftest1.pw.f1.frame.log configure -width 2500
尝试过的无效操作
遍历所有组件层级批量修改宽度:
[catch { $ww configure -width 1000} err]
该操作导致GUI布局错乱,但全局窗口尺寸依然没有变化。
内容的提问来源于stack exchange,提问作者iostrym
相关产品推荐
相关产品推荐

