【问题标题】:Tk window layout , widget size to maximizeTk 窗口布局,小部件尺寸最大化
【发布时间】:2014-11-18 23:24:50
【问题描述】:

我正在尝试使用 TK 包在 tcl 中创建一个窗口。

该窗口由 4 个文本小部件和一个菜单栏组成。

(像这样:http://artafact.be/sites/default/files/window.png

但我希望窗口最大化到屏幕。

我尝试通过以下方式做到这一点:

set widthsmall  [expr {int([winfo screenwidth  .] * 0.25)}] ....

text .main \          -width $widthsmall -height $heightbig \

但这会产生一个比屏幕更宽的窗口!

这怎么可能?

proc buildUI {} {
    global widthsmall
    global widthbig
    global heightsmall
    global heightbig
    frame .toolbar
    scrollbar .vsb -command [list .main yview]
    text .main \
        -width $widthsmall -height $heightbig \
        -yscrollcommand [list .vsb set] \
        -highlightthickness 0
   scrollbar .vsb1 -command [list .test yview]
    text .test \
        -width $widthbig -height $heightbig \
        -yscrollcommand [list .vsb1 set] \
        -highlightthickness 0

    scrollbar .vsb2 -command [list .tsvf yview]
    text .tsvf \
        -width $widthsmall -height $heightsmall \
        -yscrollcommand [list .vsb2 set] \
        -highlightthickness 0

    scrollbar .vsb3 -command [list .tobsw yview]
    text .tobsw \
        -width $widthbig -height $heightsmall \
        -yscrollcommand [list .vsb3 set] \
        -highlightthickness 0

    button .b -text start -command start_sim
    pack .b -in .toolbar -side left

    grid .toolbar -sticky nsew -column 0 -row 0 -columnspan 2
    grid .main .vsb  -sticky nsew -column 0 -row 1
    grid .test .vsb1  -sticky nsew -column 1 -row 1
    grid .tsvf .vsb2  -sticky nsew -column 0 -row 2
    grid .tobsw .vsb3 -sticky nsew -column 1 -row 2
} 

【问题讨论】:

  • 您的问题缺少代码,我们很难猜到。你如何打包或网格化它?

标签: tcl tk


【解决方案1】:

要最大化名称在变量win 中的窗口,请使用

wm state $win zoomed

在 Windows 和 Mac OS X 上,或

wm attributes $win -zoomed 1

在 X11 系统上。

要使窗口内的小部件扩展以匹配增加的窗口大小,请配置几何管理器以进行扩展。

pack .mywidget -expand 1 -fill both ;# grow in both x and y
pack .mywidget -expand 1 -fill x    ;# grow in x
pack .mywidget -expand 1 -fill y    ;# grow in y

grid rowconfigure    . .mywidget -weight 1 ;# this row will expand
grid columnconfigure . .mywidget -weight 1 ;# this column will expand

文档:gridpackwm

【讨论】:

  • 窗口中的文本字段高度和宽度将绕过该调用
  • @user1104939:文本小部件不会参与其中。您可以使用此调用最大化主窗口 (.) 或您正在使用的顶层窗口。您可以让几何管理器在最大化窗口中设置小部件的大小,也可以自己设置这些大小。
  • 但它仍然无法解决文本小部件不会随窗口调整大小的问题。我希望 2 个左侧小部件(如您在原始帖子中所见)始终为窗口的 1/4。
  • @user1104939:查看更新的答案。你要求的是这样的吗?
猜你喜欢
  • 2011-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多