[Tkinter-discuss] Tkinter TopLevel transparency

Metz, Bobby W, WWCS bwmetz at att.com
Fri Jul 7 00:16:30 CEST 2006


	Looking for help on making my toplevel window backgrounds opaque or transparent.  I've seen sparse mention of setting the alpha property of the toplevel, but the only other mention I've seen in any documentation has to do with canvas widgets.  I'm running python 2.4 and the toplevel returns an error when I try to set the alpha param.

	>>> from Tkinter import *
	>>> root = Tk()
	>>> root.wm_attributes('-alpha', 0.5)
	Traceback (most recent call last):
	  File "<pyshell#6>", line 1, in ?
	    root.wm_attributes('alpha', 0.5)
	  File "c:\python24\lib\lib-tk\Tkinter.py", line 1386, in wm_attributes
	    return self.tk.call(args)
	TclError: wrong # args: should be "wm attributes window ?-disabled ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"

I first saw this referenced on effbot.org and was hoping to use it.


In Win32 programming I know this is a two step process but haven't found any equiv documentation for Tkinter and using the Python win32 modules doesn't work as seen here for Notepad.

	import win32con
	import win32api
	import win32gui
	import winxpgui

	# Notepad window handle
	hWND = 1050292

	# Prep the window for transparency...creates buffer of some sort in Windows
	win32gui.SetWindowLong (hWND, win32con.GWL_EXSTYLE, win32gui.GetWindowLong (hWND, win32con.GWL_EXSTYLE ) | win32con.WS_EX_LAYERED )

	# Get the window background color
	bgColor = win32api.GetSysColor(win32con.COLOR_WINDOW)
	r = bgColor & 0xFF
	g = (bgColor & 0x0000FF00) >> 8
	b = (bgColor & 0x00FF0000) >> 16

	# Re-compute the RGB value to pass to the SetLayeredWindowAttributes function
	winxpgui.SetLayeredWindowAttributes(hWND, win32api.RGB(r, g, b), 50, win32con.LWA_COLORKEY|win32con.LWA_ALPHA)

Any pointers would be greatly appreciated!



More information about the Tkinter-discuss mailing list