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

yipeiwu_com7年前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相关内容感兴趣的读者可查看本站专题:《Python数据结构与算法教程》、《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

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

相关文章

python plotly画柱状图代码实例

python plotly画柱状图代码实例

这篇文章主要介绍了python plotly画柱状图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 代码 import p...

Python any()函数的使用方法

描述: 如果iterable的任何元素为true,则返回true。如果iterable为空,则返回false。相当于: def any(iterable): for elemen...

Python Datetime模块和Calendar模块用法实例分析

本文实例讲述了Python Datetime模块和Calendar模块用法。分享给大家供大家参考,具体如下: datetime模块 1.1 概述 datetime比time高级了不少,可...

Python从Excel中读取日期一列的方法

如下所示: import xlrd import datetime file=u"伏特加.xls"#注意读中文文件名稍微处理一下 data=xlrd.open_workbook(...

Python数据可视化之画图

Python数据可视化之画图

安装数据可视化模块matplotlib:pip install matplotlib 导入matplotlib模块下的pyplot 1 折线图 from matplotlib imp...