Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

displaying image using canvasHelpful Member! 

Silentkiller (TechnicalUser) (OP)
4 Mar 03 16:02
Hi!
   How can i display a *.pgm image i called, using canvas function. I'm new to Tcl/Tk.
Thankx
Helpful Member!  AviaTraining (Instructor)
5 Mar 03 12:23
Displaying an image is a 2-step process:
  1. Create an image object in memory
  2. Display the image object in the canvas (or other widget)
You create the image object with the image create command, which is where you'd specify the name of the file containing the image data. For example:

set img [image create photo -file myImg.pgm]

A couple of notes here. The example above assumes that the image file is in the current working directory. If it isn't, you can use a relative or absolutive path for the file name. The second note is that the image create command automatically creates a name for the image object, and that is the return value of the command. You'll need this image name later on, so you'll want to store it in a variable, as shown above.

Now that we've got an image object created, we can display it in our canvas (or other widget). For a canvas, you do so with the canvas's create image operation, and providing it the position and the name of the image object to display. For example:

canvas .c
pack .c -expand yes -fill both
.c create image 10 10 -anchor nw -image $img


This example tell the canvas, .c, to display the image object I created earlier so that its northwest corner (upper-left corner) is anchored to the position x=10, y=10 on the canvas.

As an aside, Tcl/Tk has built-in support only for GIF and PPM/PGM format full-color images. If you want to display images from other file formats, you'll need to download and install the Img extension, which allows you to display other formats such as JPEG, TIFF, and others.

- Ken Jones, President, ken@avia-training.com
  Avia Training and Consulting, www.avia-training.com
  866-TCL-HELP (866-825-4357) US Toll free
  415-643-8692 Voice
  415-643-8697 Fax

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close