Ruby/Tk:如何使用图像获得更小的按钮小部件
我正在 Mac OS X 10.6 上的 Ruby 1.8.7 上使用 ActiveTcl 在 Tk 8.5.9 上进行编码。
为了满足我的应用程序要求,我需要使按钮小部件与 gif 图像一样小,但我无法做到。我花了几个小时进行搜索和实验,结果却是负面的。
提前非常感谢您提供任何线索。
以下是我试图从中获取小按钮的代码。
require 'tk'
require 'tkextlib/tile'
$up_img = TkPhotoImage.new("file"=>"arrowup-n.gif")
$down_img = TkPhotoImage.new("file"=>"arrowdown-n.gif")
root = TkRoot.new {title "Ek Composer"}
content = Tk::Tile::Frame.new(root).pack
Tk::Tile::Button.new(content) {width 1;image $up_img; command {move_up} }.pack
Tk::Tile::Button.new(content) {width 1;image $down_img;command {move_down}}.pack
def move_up
p "move up"
end
def move_down
p "move down"
end
Tk.mainloop
但按钮仍然太大:(。
I'm coding on Tk 8.5.9 from ActiveTcl on Ruby 1.8.7 on a Mac OS X 10.6.
To meet my application requirements I need to make the button widgets as small as the gif image but I am not able to. I have been hours searching and experimenting with negative results.
Greatly thankful in advance for any clues.
Following is the code i am trying to get small buttons from.
require 'tk'
require 'tkextlib/tile'
$up_img = TkPhotoImage.new("file"=>"arrowup-n.gif")
$down_img = TkPhotoImage.new("file"=>"arrowdown-n.gif")
root = TkRoot.new {title "Ek Composer"}
content = Tk::Tile::Frame.new(root).pack
Tk::Tile::Button.new(content) {width 1;image $up_img; command {move_up} }.pack
Tk::Tile::Button.new(content) {width 1;image $down_img;command {move_down}}.pack
def move_up
p "move up"
end
def move_down
p "move down"
end
Tk.mainloop
But the buttons remain too big :(.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很尴尬。 OSX 主题确实希望在按钮的两端添加额外的空间。
您可以尝试切换到经典按钮(在
tk
本身中),但这会在垂直方向上放置更多空间,并且看起来不太原生。或者,您可以将图像放入标签中(可以精确缩小)并向其添加绑定以使其响应鼠标单击。It's awkward. The OSX theme really wants to add extra space at either end of the button.
You can try switching to the classic button (in
tk
itself) but that puts more space vertically and looks a bit less native. Or you can put the image in a label (which you can shrink exactly) and add bindings to it to make it respond to mouse clicks.我添加了标签绑定。工作正常。谢谢。遵循带有绑定作为按钮的标签代码片段。
I added binding to label. Works fine. Thanks. Follows a code snippet of label with binding as button.