本文實例講述了Python使用Windows API創建窗口。分享給大家供大家參考,具體如下:
一、代碼
# -*- coding:utf-8 -*-#! python3import win32guifrom 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 + 1wc.hCursor = win32gui.LoadCursor(0,IDI_APPLICATION)wc.lpszClassName = "Python no Windows"wc.lpfnWndProc = WndProcreg = 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程序設計有所幫助。
新聞熱點
疑難解答