Tcl 如何限制按钮';它有图像时的大小是多少?

Tcl 如何限制按钮';它有图像时的大小是多少?,tcl,tk,Tcl,Tk,我正在Tk中试用按钮,并已将图像加载到按钮: package require Tk image create photo myimage -file "../button.png" ttk::button .button -image myimage place .button -x 0 -y 0 但是,button.png图像非常大(200x100),因此按钮会调整自身大小以显示整个图像。是否可以将按钮调整为特定大小,例如100x50(可能通过使用网格布局?),并让按钮重新采样其图像,使

我正在Tk中试用按钮,并已将图像加载到按钮:

package require Tk

image create photo myimage -file "../button.png"
ttk::button .button -image myimage

place .button -x 0 -y 0
但是,
button.png
图像非常大(200x100),因此按钮会调整自身大小以显示整个图像。是否可以将按钮调整为特定大小,例如100x50(可能通过使用网格布局?),并让按钮重新采样其图像,使其适合按钮?

Tk的按钮类(
button
ttk::button
)通过调整自身大小以精确包含内容来处理图像。他们从不自动对图像进行重采样(一般来说,这有点棘手,因为正确的方法取决于图像内容的细节);你必须自己做

image create photo myimage -file "../button.png"
set subsampled [image create photo]
$subsampled copy myimage -subsample 2 2
ttk::button .button -image $subsampled

place .button -x 0 -y 0
Tk的内置子采样代码不是很好!如果你知道你在用图像处理做什么(好吧,比我多!),那么你可能会用它做得更好。但我只是看了一下
卷曲抽取xy
的文档——这似乎是正确的——然后挠头