in reply to Masking Tk Canvas

You are not very clear as to what your ultimate objective is. From your graphic, you could just make a rectangle on the exiting canvas, and put your text into it. You can set the -tags of all the canvas objects, then layer them by using lower and raise. Do you really need 2 canvases?

When you place a new object on a canvas, it will obscure what is below it, and what is below, will reappear when the new object is removed.


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Masking Tk Canvas
by avo (Pilgrim) on Sep 17, 2005 at 20:53 UTC
    Ok, I agree. I wasn't quite clear. So.. let me explain it in more details. Imagine you have a canvas, on which you just create a pattern of PNG files with Alpha transparency (ei. background is transparent). Then you want to create a second pattern that is like - a second layer with another PNG. But you want to mask it (ie crop the layer with an rectangular shape) so you can move the contents of it inside the mask. Perhaps because my English is not great, I just created a small Flash demonstration that will give you an idea... I am not sure whether a normal canvas can mask like this.... have a look here
      I looked at your flash, and wasn't sure exactly what it was supposed to do, different from what I suggested earlier. Also the text in the "floater" seemed to move around inside the rectangle as the rectangle moved. I don't know if that was one of the things you want to accomplish, probably not. Also, I did not see any "transparency effects" in your flash.

      But setting aside the transparency and alpha-layering stuff, which I'm not sure about in Tk, you could simulate your flash in Tk, by just creating an a new 'image' on your existing canvas, and setting tags on it, to make it "draggable".

      Perhaps, if you told us what this is supposed to perform, it would be easier. Are you trying to "custom-drag" images to positions on a canvas, to build a new composite image?

      I have seen one other thing which may be what you are looking for. It's in the TkZinc demo, and is called the "magic lens", (it is #6 under Small Applications).


      I'm not really a human, but I play one on earth. flash japh
        Yeah. Basicaly I need the internal movement. I just want to create a layer in the same canvas with rectangular shape which contains much more than the rectangle and then move the contents in the second layer. 1st the contents itself that has been masked and second- the whole layer - which consists of this rectangle masking. I agree about Zinc, I've seen the zooming glass. The idea is the following, I am trying to make a single canvas in which I want to have sort of a background pattern and then a second (may be canvas) layer that has image items which must be scrolled in pages (like a list). I don't think this can be acheived trough the ordinary canvas (Tk::Canvas) using only one canvas widget, that's why I am thinking that the best is to create a second widget and use ->place geometry manager to possition it relatively from the 0,0 of the background canvas... The problem that comes with this is that there is no way to make the background of the second canvas transparent so the user can see trought the top widget wherever there is no content - the bottom widget. I am not showing this in the flash sample... Anyway... Thanks a lot for the reply. I've been just wandering whether something like canvas in canvas can be acheived using the standard Tk canvas. :) Thanks again!!!