python处理按钮消息的实例详解

yipeiwu_com6年前Python基础

python处理按钮消息的实例详解

           最新学习Python的基础知识,在论坛中看到不错的实例,这里记录下,也希望能帮助到大家,

效果图:

实现代码:

import win32ui
import win32con
from pywin.mfc import dialog
classMyDialog(dialog.Dialog):
defOnInitDialog(self):
    dialog.Dialog.OnInitDialog(self)
    self.HookCommand(self.OnButton1,1051)
    self.HookCommand(self.OnButton2,1052)
defOnButton1(self,wParam,lParam):
    win32ui.MessageBox('Button1',\
'Python',\
              win32con.MB_OK)
    self.EndDialog(1)
defOnButton2(self,wParam,lParam):
    text = self.GetDlgItemText(1054)
    win32ui.MessageBox(text,\
'Python',\
              win32con.MB_OK)
    self.EndDialog(1)
style =(win32con.DS_MODALFRAME|
     win32con.WS_POPUP|
     win32con.WS_VISIBLE|
     win32con.WS_CAPTION|
     win32con.WS_SYSMENU|
     win32con.DS_SETFONT)
childstyle =(win32con.WS_CHILD|
       win32con.WS_VISIBLE)
buttonstyle =win32con.WS_TABSTOP|childstyle
di =['Python',
(0,0,300,180),
   style,
None,
(8,"MS Sans serif")]
Button1=(['Button',
'Button1',
1051,
(80,150,50,14),
     buttonstyle|win32con.BS_PUSHBUTTON])
Button2=(['Button',
'Button2',
1052,
(160,150,50,14),
     buttonstyle|win32con.BS_PUSHBUTTON])
stadic =(['Static',
'Python Dialog',
1053,
(130,50,60,14),
     childstyle])
Edit=(['Edit',
"",
1054,
(130,80,60,14),
     childstyle|win32con.ES_LEFT|
     win32con.WS_BORDER|win32con.WS_TABSTOP])
init =[]
init.append(di)
init.append(Button1)
init.append(Button2)
init.append(stadic)
init.append(Edit)
mydialog =MyDialog(init)
mydialog.DoModal()

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

python字典的遍历3种方法详解

python字典的遍历3种方法详解

遍历字典: keys() 、values() 、items()   1. xxx.keys() : 返回字典的所有的key 返回一个序列,序列中保存有字典的所有的键   效果图:   ...

python之cv2与图像的载入、显示和保存实例

python之cv2与图像的载入、显示和保存实例

本文是OpenCV 2 Computer Vision Application Programming Cookbook读书笔记的第一篇。在笔记中将以Python语言改写每章的代码。 P...

对python调用RPC接口的实例详解

要调用RPC接口,python提供了一个框架grpc,这是google开源的 rpc相关文档: https://grpc.io/docs/tutorials/basic/python.h...

TensorFlow索引与切片的实现方法

TensorFlow索引与切片的实现方法

索引与切片在Tensorflow中使用的频率极其高,可以用来提取部分数据。 1.索引 在 TensorFlow 中,支持基本的[𝑖][𝑗]…标准索引方...

对pandas进行数据预处理的实例讲解

参加kaggle数据挖掘比赛,就第一个赛题Titanic的数据,学习相关数据预处理以及模型建立,本博客关注基于pandas进行数据预处理过程。包括数据统计、数据离散化、数据关联性分析 引...