Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is 'partial transparency' possible?

73 views
Skip to first unread message

Helmut Giese

unread,
Sep 7, 2021, 4:40:50 PM9/7/21
to
Hello out there,
I had this idea: In a rather complicated configuration environment I
would like to somehow 'gray out' sections which are currently not
relevant - as if some sort of fog covers it.
Is there some picture format which supports this 'partial
transparency'? or maybe an extension?
I am on Windows with tcl 8.6.10.

Any link or hint or idea will be greatly appreciated.
Helmut

Uwe Klein

unread,
Sep 8, 2021, 3:58:02 AM9/8/21
to
Am 07.09.21 um 22:40 schrieb Helmut Giese:
there is bitmapped transparency around.

afair works with gif, png, ?
( but I've only ever used it while
massaging pics via the netpbm package.)

Uwe

Christian Gollwitzer

unread,
Sep 8, 2021, 4:10:37 AM9/8/21
to
Am 07.09.21 um 22:40 schrieb Helmut Giese:
> Hello out there,
> I had this idea: In a rather complicated configuration environment I
> would like to somehow 'gray out' sections which are currently not
> relevant - as if some sort of fog covers it.
> Is there some picture format which supports this 'partial
> transparency'?

This is called an "Alpha channel" and supported by PNG.

Christian

Helmut Giese

unread,
Sep 8, 2021, 10:44:46 AM9/8/21
to
Hi Christian,
thanks, it is so good that there are knowlegeable people around here.
However I can't get it to work: Every image command I tried rejects
the option '-alpha'. Do you maybe have an example of its use?
Thank you
Helmut

Harald Oehlmann

unread,
Sep 8, 2021, 10:56:59 AM9/8/21
to
TCL version ?
It was added somewhere in 8.6.x AFAI remember..

Ralf Fassel

unread,
Sep 8, 2021, 11:21:11 AM9/8/21
to
* Helmut Giese <hgi...@ratiosoft.com>
| However I can't get it to work: Every image command I tried rejects
| the option '-alpha'. Do you maybe have an example of its use?

Check the photo(n) manpage:

https://www.tcl.tk/man/tcl/TkCmd/photo.html

FORMAT SUBOPTIONS
Some image formats support sub-options, which are specified at
the time that the image is loaded using additional words in the
-format option. At the time of writing, the following are
supported:

png -alpha alphaValue
An additional alpha filtering for the overall image, which
allows the background on which the image is displayed to
show through. This usually also has the effect of
desaturating the image. The alphaValue must be between 0.0
and 1.0.

--<snip-snip>--

The PNG image loader allows the application of an additional
alpha factor during loading, which is useful for generating
images suitable for disabled │ buttons: │

image create photo icon -file "icon.png" │
image create photo iconDisabled -file "icon.png" \ │
-format "png -alpha 0.5" │
button .b -image icon -disabledimage iconDisabled │

HTH
R'

Helmut Giese

unread,
Sep 8, 2021, 1:43:15 PM9/8/21
to
Arrgh,
> image create photo icon -file "icon.png" ?
> image create photo iconDisabled -file "icon.png" \ ?
> -format "png -alpha 0.5" ?
I didn't have the idea to /quote/ the option and did
image create ... -format png -alpha .05
Thanks a lot Ralf.
However, I have another problem: Since Tk cannot handle an image by
itself it needs a "container" - e.g. a label or a button. Now if I
use a label this label itself has a bottom that is not transparent -
so it seems impossible to achieve what I intended.
Hm, another 'tot geborene Idee' (idea born dead) - nothing new to me
:(

Thanks to all of you who responded.
Helmut

Rich

unread,
Sep 8, 2021, 1:58:00 PM9/8/21
to
If you use the plain Tk label widget, and turn off all the
default configuration options that provide borders/etc., you can get a
"container" for the image that is just the image pixels and nothing
more.

Experimenting in a REPL with an image in a label and running
interactive "label configure ..." to change things will reveal which
ones need to be adjusted.

Schelte

unread,
Sep 8, 2021, 3:30:04 PM9/8/21
to
On 08/09/2021 19:57, Rich wrote:
> If you use the plain Tk label widget, and turn off all the
> default configuration options that provide borders/etc., you can get a
> "container" for the image that is just the image pixels and nothing
> more.
>
But it will not be transparent and show the underlying widgets.

You can however make a (semi-)transparent toplevel:

toplevel .t -background black
wm attributes .t -alpha 0.5
wm overrideredirect .t 1

But then you'll somehow need to put the toplevel over the desired area,
and update the position whenever the application window is moved,
resized, or (partly) obscured:
wm geometry .t 400x100+10+10

That's going to be a lot of work.


Schelte.

Christian Gollwitzer

unread,
Sep 9, 2021, 1:44:28 AM9/9/21
to
Am 08.09.21 um 21:29 schrieb Schelte:
Ah, I did'nt realise at first that you want to obscure a window or frame
/partially/ with a semitransparent window.

Schelte's suggestion reminds me of the way "tk busy" works. IMHO it is a
hack, but when you do "tk busy <window>" then that window is covered
with a fully transparent overlay so that mouse clicks do not reach it
anymore. Maybe there is a way to set the "busy window" to an
intermediate transparency?

Christian

Donal K. Fellows

unread,
Sep 18, 2021, 4:01:06 AM9/18/21
to
On Thursday, 9 September 2021 at 06:44:28 UTC+1, Christian Gollwitzer wrote:
> Schelte's suggestion reminds me of the way "tk busy" works. IMHO it is a
> hack, but when you do "tk busy <window>" then that window is covered
> with a fully transparent overlay so that mouse clicks do not reach it
> anymore. Maybe there is a way to set the "busy window" to an
> intermediate transparency?

That's an InputOnly window (on X11) and it can't be drawn on at all.

Donal.
0 new messages