1

不是 wx、gtk3、pyqt 等...我需要类似的东西:

cef.Initialize(settings=settings) window_info = cef.WindowInfo() browser = cef.CreateBrowserSync(url="localhost:8080/", window_title="Hello World!" icon="myicon.png" )

4

1 回答 1

0

在 Linux 上,使用函数或类似函数xseticon以编程方式执行程序,请参阅:http: //www.leonerd.org.uk/code/xseticon/os.system()

在 Windows 上使用 ctypes 内置 Python 模块来执行本机 win32 函数。下面的示例代码。该_hWnd变量保存窗口句柄,可以通过调用browser.GetWindowHandle().

from ctypes import *
from ctypes.wintypes import *
from os import path
import platform

LRESULT = c_int64 if platform.architecture()[0] == "64bit" else c_long

SendMessage = windll.user32.SendMessageW
SendMessage.restype = LRESULT
SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]

GetModuleHandle = windll.kernel32.GetModuleHandleW
GetModuleHandle.restype = HMODULE
GetModuleHandle.argtypes = [LPCWSTR]

IMAGE_ICON = 1
LR_LOADFROMFILE = 0x00000010
LR_CREATEDIBSECTION = 0x00002000

LoadImage = windll.user32.LoadImageW
LoadImage.restype = HANDLE
LoadImage.argtypes = [HINSTANCE, LPCWSTR, UINT, c_int, c_int, UINT]

RelPath = lambda file : path.join(path.dirname(path.abspath(__file__)), file)


def AlterIcon(_hWnd, lpszIcon):

    WM_SETICON = 0x0080
    ICON_BIG = 1

    hModel = GetModuleHandle(None)
    hIcon = LoadImage(hModel,
                      RelPath(lpszIcon),
                      IMAGE_ICON,
                      0, 0,
                      LR_LOADFROMFILE | LR_CREATEDIBSECTION)


    SendMessage(_hWnd, WM_SETICON, ICON_BIG, hIcon)

参考:http: //qaru.site/questions/7837596/how-to-include-image-in-message-box-using-ctypes-in-python

于 2019-02-12T17:21:08.470 回答