Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks I am in need of assistance.

Is it possible to have two canvases in one Tk window? I'm trying to have a background image and an active canvas, but I'm not having a whole lot of luck.

I've read and re-read Mastering Tk and can't find an answer to my query.

I assumed that the easiest way to put a bg image would be to put it in a canvas and then place it where I wanted it, rather than making a button with an image on it.

However, my second canvas is also displaying the image of the first canvas, even though I've specified a different file to display.

Is it something as simple as changing the focus of the bg canvas? Or am I overlooking something simple here?

Any help would be greatly appreciated!

Replies are listed 'Best First'.
Re: Multiple canvases in Tk?
by {NULE} (Hermit) on May 04, 2002 at 22:15 UTC
    Hi Popcorn Dave,

    I think we may need a bit more information here. It sounds like you want one Canvas on top of another. If the reason you want that is to have a background, it is probably a waste of time to do so with two Canvas widgets.

    Canvas widgets give you the ability to specify how objects are layered on them. Specifically you would assign a Tag to an item then use the $canvas->lower() and $canvas->raise() methods to control which are drawn on top.

    But the easiest thing to do is draw your background first. Then you are done unless you accidentally lower another object below it.

    Hope this helps - if not post some code and myself and other monks will be sure to take a look at it. Good luck,
    {NULE}
    --
    http://www.nule.org