# Newbie question Canvas or frame

**URL:** <https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624>\
**Category:** Ruby\
**Created:** [October 10, 2006, 12:19pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624 "2006-10-10T12:19:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 10, 2006, 12:19pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/1 "2006-10-10T12:19:25Z")

</div>

In ruby-tk

Do you need a canvas to show a picture or is it ok to  
show a picture on a frame?

When should you use a canvas?

---

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 10, 2006, 12:46pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/2 "2006-10-10T12:46:39Z")

</div>

Mer G. wrote:

> In ruby-tk  
> Do you need a canvas to show a picture or is it ok to  
> show a picture on a frame?  
> When should you use a canvas?

Ok. canvas is needed to display picture.  
but i still would like to hear peoples comments about  
canvases and frames to understand them better.

---

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 10, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/3 "2006-10-10T15:58:58Z")

</div>

From: Mer G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Newbie question Canvas or frame  
Date: Tue, 10 Oct 2006 19:19:28 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> In ruby-tk  
> Do you need a canvas to show a picture or is it ok to  
> show a picture on a frame?

If you want to show a picture only, you don’t need a canvas widget.  
Please create a TkPhotoImage object and assign it to `image' option of a TkLabel object (or a widget which has `image’ option).

Current standard Tcl/Tk suuports only GIF and PPM/PGM formats.  
If you want to treat other formats (JPEG, BMP, and so on), you need  
to use `TkImg’ extension (ActiveTcl package already includes it).  
Current Ruby/Tk supports TkImg extension.

> When should you use a canvas?

There are many cases.

- When needs a drawing field (and save it by Postscrpt format).

- When want to handle widgets or canvas items (Line, Oval, and so on)  
by coordinates.  
Please see the example “Ruby/Tk widget demo” which is included in  
Ruby source archive.

- When want to assign bindings to some parts of a picture  
(e.g. a tree picture which has clickable branches).

- When want to create a scrollable frame.  
Please see the example “ext/tk/sample/scrollframe.rb” on Ruby  
source tree.

# On Ruby/TkORCA, a canvas widget takes place of a pseudo window

# manager for slave Ruby/Tk applications.

---

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 10, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/4 "2006-10-10T16:20:37Z")

</div>

Hidetoshi NAGAI wrote:

> If you want to show a picture only, you don’t need a canvas widget.  
> Please create a TkPhotoImage object and assign it to `image' option of a TkLabel object (or a widget which has`image’ option).

Ah. Im using TkPhotoImage with canvas and a frame. Is this ok ?

And the `TkImg’ extension, do I add that with require “TKImg”.  
I have active tcl on the computer.

---

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 13, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/5 "2006-10-13T15:36:18Z")

</div>

Thank You!

---

<div class="post-metadata">

**Author:** ![merrua](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@merrua](https://www.ruby-forum.com/u/merrua)\
**Post date:** [October 10, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/newbie-question-canvas-or-frame/71624/6 "2006-10-10T18:13:56Z")

</div>

From: Mer G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Newbie question Canvas or frame  
Date: Tue, 10 Oct 2006 23:20:40 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Ah. Im using TkPhotoImage with canvas and a frame. Is this ok ?

That is OK, if that is what you want. 🙂

> And the `TkImg’ extension, do I add that with require “TKImg”.  
> I have active tcl on the computer.

Please use “require ‘tkextlib/tkimg’”.  
If your Ruby/Tk loads libraries of ActiveTcl, that will work.
