在当前移动的窗口上画一个圆(Python)

2024-05-31 23:40:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用python时遇到了一个问题。 我想在监视器上画一个圆圈。在

假设我打开了我的浏览器,我想让圆圈自己旋转,并能用鼠标按我想要的任何按钮。在

我的想法是,由于跳跃运动,圆圈与我的手部运动相连,我想在能够使用鼠标的同时显示我所做的手势。在

我担心的是我必须做一个不允许我使用鼠标的透明窗口,因为我会在透明窗口上粘上。在

谢谢!在


Tags: 浏览器鼠标按钮监视器手势我会手部圆圈
1条回答
网友
1楼 · 发布于 2024-05-31 23:40:42

找到了解决方案,我用了wxPython

代码下方:

    import wx, inspect, os, sys, win32gui

IMAGE_PATH = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + '\cerchio.png'


class Cursor(wx.Frame):
    def __init__(self, parent, log):
        self.log = log
        self.delta = wx.Point(0,0)
        wx.Frame.__init__(self, parent, -1, "Shaped Window",
                                style =
                                wx.FRAME_SHAPED
                                | wx.SIMPLE_BORDER
                                | wx.FRAME_NO_TASKBAR
                                | wx.STAY_ON_TOP
                                )


        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER,         self.update, self.timer)
        self.Bind(wx.EVT_PAINT,         self.OnPaint)

        self.x=0
        self.y=0
        self.hasShape = False
        self.SetClientSize( (50, 50) )
        image = wx.Image(IMAGE_PATH, wx.BITMAP_TYPE_PNG)
        image.SetMaskColour(255,255,255)
        image.SetMask(True)            
        self.bmp = wx.BitmapFromImage(image)

        self.SetWindowShape()
        self.timer.Start(1)
        dc = wx.ClientDC(self)

        dc.DrawBitmap(self.bmp, 0, 0, True)


    def OnExit(self, evt):
        self.Close()

    def SetWindowShape(self, *evt):
        # Use the bitmap's mask to determine the region
        r = wx.RegionFromBitmap(self.bmp)
        self.hasShape = self.SetShape(r)

    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self.bmp, 0, 0, True)


    def OnExit(self, evt):
        self.Close()

    def update(self, event):
        #self.x, self.y = win32gui.GetCursorPos()
        self.SetPosition((self.x,self.y))



if __name__ == '__main__':

    app = wx.App( False )
    frm = Cursor(None, -1)
    frm.Show()



    app.MainLoop()

这将50x50的白色背景png图像(修改图像路径)映射到光标位置(虽然您无法单击)

相关问题 更多 >