rec*_*gle 2 macros winapi pywin32 ctype
我正在尝试使用SetLayeredWindowAttributes函数来更改窗口透明度颜色。我使用 ctypes 模块创建了一个结构。我很确定我必须使用COLORREF RGB 宏才能使其正常工作。
如何在使用 ctypes 生成的结构上使用宏?
我要去做什么。
import Tkinter as tk
import win32gui
import win32con
class ColorRef (ctypes.Structure) :
_fields_ = [("byRed", ctypes.c_byte),
("byGreen", ctypes.c_byte),
("byBlue", ctypes.c_byte)]
# makes a Tkinter window
root = tk.Tk()
# a handle to that window
handle = int(root.wm_frame(), 0)
# a COLORRED struct
colorref = ColorRef(1, 1, 1)
# attempting to change the transparency color
win32gui.SetLayeredWindowAttributes(handle, colorref, 0, win32con.LWA_COLORKEY)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
三件事:
0x00bbggrr值。所以代码看起来像这样:
def RGB(r, g, b):
r = r & 0xFF
g = g & 0xFF
b = b & 0xFF
return (b << 16) | (g << 8) | r
colour = RGB(1, 1, 1)
win32gui.SetLayeredWindowAttributes(handle, colour, 0, win32con.LWA_COLORKEY)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1204 次 |
| 最近记录: |