网络编程
位置:首页>> 网络编程>> Python编程>> Python使用Windows API创建窗口示例【基于win32gui模块】

Python使用Windows API创建窗口示例【基于win32gui模块】

作者:chengqiuming  发布时间:2021-04-14 02:01:10 

标签:Python,创建窗口

本文实例讲述了Python使用Windows API创建窗口。分享给大家供大家参考,具体如下:

一、代码


# -*- coding:utf-8 -*-
#! python3
import win32gui
from win32con import *
def WndProc(hwnd,msg,wParam,lParam):
 if msg == WM_PAINT:
   hdc,ps = win32gui.BeginPaint(hwnd)
   rect = win32gui.GetClientRect(hwnd)
   win32gui.DrawText(hdc,'GUI Python',len('GUI Python'),rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER)
   win32gui.EndPaint(hwnd,ps)
 if msg == WM_DESTROY:
   win32gui.PostQuitMessage(0)
 return win32gui.DefWindowProc(hwnd,msg,wParam,lParam)
wc = win32gui.WNDCLASS()
wc.hbrBackground = COLOR_BTNFACE + 1
wc.hCursor = win32gui.LoadCursor(0,IDI_APPLICATION)
wc.lpszClassName = "Python no Windows"
wc.lpfnWndProc = WndProc
reg = win32gui.RegisterClass(wc)
hwnd = win32gui.CreateWindow(reg,'www.jb51.net - Python',WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,0,None)
win32gui.ShowWindow(hwnd,SW_SHOWNORMAL)
win32gui.UpdateWindow(hwnd)
win32gui.PumpMessages()

二、运行结果:

Python使用Windows API创建窗口示例【基于win32gui模块】

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/chengqiuming/article/details/78601000

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com