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

yipeiwu_com7年前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中字典的setdefault()方法教程

前言 在python基础知识中有说过,字典是可变的数据类型,其参数又是键对值。setdefault()方法和字典的get()方法在一些地方比较相像,都可以得到给定键对应的值。但setde...

python实现自动化上线脚本的示例

程序说明: 本程序实现将开发程序服务器中的打包文件通过该脚本上传到正式生产环境(注:生产环境和开发环境不互通) 程序基本思路: 将开发环境中的程序包拷贝到本地堡垒机 将程序包进行解压 获...

tensorflow更改变量的值实例

如下所示: from __future__ import print_function,division import tensorflow as tf #create a Var...

利用Python将时间或时间间隔转为ISO 8601格式方法示例

利用Python将时间或时间间隔转为ISO 8601格式方法示例

前言 大家都知道,Python自带的datetime库提供了将datetime转为ISO 8610格式的函数,但是对于时间间隔(inteval)并没有提供转换的函数,下面我们动手写一个。...

在Python中画图(基于Jupyter notebook的魔法函数)

这篇文章主要介绍了在Python中画图(基于Jupyter notebook的魔法函数),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...