# Tk buttons with images?

**URL:** <https://www.ruby-forum.com/t/tk-buttons-with-images/180077>\
**Category:** Ruby\
**Created:** [December 11, 2009, 12:41am UTC](https://www.ruby-forum.com/t/tk-buttons-with-images/180077 "2009-12-11T00:41:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [December 11, 2009, 12:41am UTC](https://www.ruby-forum.com/t/tk-buttons-with-images/180077/1 "2009-12-11T00:41:51Z")

</div>

Hello Ive been playing around with ruby Tk to build a UI for a few new  
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  
examples

Thanks Gabriel

---

<div class="post-metadata">

**Author:** ![GabrielG1976](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8491ac/32.png) [@GabrielG1976](https://www.ruby-forum.com/u/GabrielG1976)\
**Post date:** [December 11, 2009, 6:17am UTC](https://www.ruby-forum.com/t/tk-buttons-with-images/180077/2 "2009-12-11T06:17:10Z")

</div>

From: GabrielG1976 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Tk buttons with images ?  
Date: Fri, 11 Dec 2009 08:40:08 +0900  
Message-ID:  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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.
