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实现数据的透视表的方法

在处理数据时,经常需要对数据分组计算均值或者计数,在Microsoft Excel中,可以通过透视表轻易实现简单的分组运算。而对于更加复杂的分组运算,Python中pandas包可以帮助...

实例讲解python中的序列化知识点

在程序运行的过程中,所有的变量都是在内存中,比如,定义一个dict: d = dict(name='Bob', age=20, score=88) 可以随时修改变量,比如把name...

Python import与from import使用及区别介绍

下面介绍下Python import与from import使用,具体内容如下所示: Python程序可以调用一组基本的函数(即内建函数),比如print()、input()和len()...

Python字符串的常见操作实例小结

本文实例讲述了Python字符串的常见操作。分享给大家供大家参考,具体如下: 如果我们想要查看以下功能:help(mystr .find) 1.find 例: mystr="hell...

将tensorflow.Variable中的某些元素取出组成一个新的矩阵示例

在神经网络计算过程中,经常会遇到需要将矩阵中的某些元素取出并且单独进行计算的步骤(例如MLE,Attention等操作)。那么在 tensorflow 的 Variable 类型中如何做...