窗口移动时,会触发wx.EVT_MOVE事件;调整窗口大小时,会触发wx.EVT_SIZE事件;窗口最小化(缩放到任务栏)时,会触发wx.EVT_ICONIZE事件。用Bind()方法绑定到自定义函数,就可以实现你想要的功能。
程序清单:win_event.py
import wx
# 继承Frame
class WInEvent(wx.Frame):
def __init__(self, *args, **kwargs):
super(WInEvent, self).__init__(*args, **kwargs)
# 初始化窗口UI
self.init_ui()
def init_ui(self):
# 窗口移动事件
self.Bind(wx.EVT_MOVE, self.move)
# 窗口改变大小事件
self.Bind(wx.EVT_SIZE, self.change, self)
# 窗口最小化事件
self.Bind(wx.EVT_ICONIZE, self.icon)
self.SetSize(900, 500)
self.SetTitle("窗口事件处理")
self.Centre()
self.Show(True)
# 移动窗口
def move(self, e):
x, y = e.GetPosition()
print("X轴坐标:%f,Y轴坐标:%f" % (x, y))
# 改变窗口大小
def change(self, e):
print(e)
x, y = e.GetSize()
print("窗口宽=%f,高=%f