in reply to Perl/Tk and Transparent Canvases

In case you haven't tried out the "widget" demo script that comes with the Tk modules, just run "widget" from a command line, and check out the last item in the "Canvases" section of the demo main window ("8. Tiles and transparent images"); the commentary and sample code provided there should get you started.

You might need to use the "place" geometry manager (perldoc Tk::place), in order to get your canvas to sit on top of other widgets, or maybe the "tile" arrangement shown in the widget demo will suffice.

Binding the mapping/unmapping of the overlay canvas (or tile) to mouse button events should be doable (Tk::bind, Tk::events), but maybe you want to think a little more about how the user is going to control things and make selections from the popup menu. (Will you need to hold the mouse button down while moving it to the object to be selected then release to select, or will consecutive clicks toggle the presence of the overlay canvas and make the selection?)

Replies are listed 'Best First'.
Re^2: Perl/Tk and Transparent Canvases
by Mikster (Acolyte) on Aug 02, 2005 at 20:36 UTC
    Many thanks for the detailed response...

    I am aware of how to put transparent objects on the canvas, but what I'm looking for is a way to make the canvas itself (which, now that I think about it, means the canvas and the Mainwindow) transparent. In other words, if you open a window with a transparent background and no window decoration, you'd see... nothing. I want the graphical equivalent of a piece of plate glass, so that I can "paint" control elements on it, and have it pop up such that the control elements appear to overlay whatever is on the screen.

    Now, a Menu widget lets you pop up Menu buttons that can be made to appear near the cursor location, so maybe what I'm really looking for is a custom widget derived from the Menu widget. Hmmmm....

      Um, if you're talking about your transparent canvas (or your popup menu) being its own separate app, distinct from other apps (or the user's "desktop") that make up the things that are always visible, then you might run into some issues with input focus.

      I'm a little rusty on the details for X (and I have only limited knowledge of MS-windows), but as a rule, any user input event (mouse click or keystroke) is normally available to only one app: the one that currently holds input focus, which is typically one whose window is on top. So if your "plate glass" interface is always on top, it might be tough to allow the user to interact directly with anything underneath it. (Or perhaps that is your intention?)

      If your "always-visible" background and your "usually invisible" control widgets are all part of the same Tk app, then I believe there is a way to handle the input events such that widgets at lower layers get a chance to see them (but I've never tried that, so I'm not sure).

        What I have in mind is a small canvas (with transparent background and now window decoration) that pops up under the cursor when a mouse button is pressed, and upon which canvas items like circles, polygons, etc. are drawn to act as control elements. I know I can do everything I need to do to make this work except put up a mainwindow whose background has a stipple of "transparent", and containing a canvas which also has a transparent background.

        That's the key element I can't seem to figure out how to do (and suspect can't be done without me doing something drastic like writing my own version of a canvas and/or mainwindow).

        If I can't do it, I'll have to settle for the less aesthetically pleasing (and content occluding) grey background.