python 基于GUI 获取鼠标位置

# _*_ coding: utf-8 _*_
__author__ = 'pythonwu'
__date__ = "2018/5/14 18:47"

import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,u"显示鼠标位置",size = (300,300))
panel = wx.Panel(self,-1)
panel.Bind(wx.EVT_MOTION,self.OnMove)
wx.StaticText(panel,-1,"Pos:",pos=(10,12))
self.posCtrl = wx.TextCtrl(panel,-1,"",pos=(40,10))

def OnMove(self,event):
pos = event.GetPosition()
self.posCtrl.SetValue('%s,%s' %(pos.x,pos.y))

if __name__ =='__main__':
# app = wx.App(False)
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
posted @ 2018-05-15 17:52  五等码农  阅读(2416)  评论(0编辑  收藏  举报