From: Hidetoshi NAGAI Date: 2009-12-11T14:16:21+09:00 Subject: Re: Tk buttons with images ? From: GabrielG1976 Subject: Tk buttons with images ? Date: Fri, 11 Dec 2009 08:40:08 +0900 Message-ID: <07a47763-89a6-4ac7-a9ba-e1aae6d5c71d@f20g2000prn.googlegroups.com> > music ruby apps I was wondering if anyone knew how to get a image to > display for a button? Ive looked around but didn't find any real world Please create a TkPhotoImage object and 'image' option of button widgets. For example, ------------------------------------- img = TkPhotoImage.new(:file=>your_image_file_name) btn = TkButton.new(base, :image=>img).pack ------------------------------------- See the Ruby/Tk WidgetDemo (ext/tk/sample/demos-en/widget on a Ruby source). It includes examples of label widgets with a image. TkButton class is a subclass of TkLabel. So, same ways are available for button widgets. Standard Tcl/Tk can support only GIF and PPM/PGM formats. If you want to use other formats (BMP, JPEG, PNG, and so on), you must use TkImg extention (ActiveTcl package includes TkImg extension). When "require 'tkextlib/tkimg'" returns true, your Ruby/Tk (Tcl/Tk) has TkImg extension. Otherwise, you must install TkImg extension for your *Tcl/Tk* libraries which used by Ruby/Tk. -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)