python用 号画空心矩形,如何使用Python在屏幕上绘制空白矩形

本文介绍了如何使用Python的win32gui模块在屏幕上绘制跟随鼠标移动的空心矩形。通过InvalidateRect解决屏幕更新问题,并讨论了提高性能的优化方案,如使用win32ui.Rectangle或DrawFocusRect。还提到了高DPI系统可能带来的定位问题及其解决方案。
摘要由CSDN通过智能技术生成

I am not an expert and I am trying to show a rectangle on screen which follows mouse movements from a settle starting point, just as when you select something in word or paint. I came with this code:

import win32gui

m=win32gui.GetCursorPos()

while True:

n=win32gui.GetCursorPos()

for i in range(n[0]-m[0]):

win32gui.SetPixel(dc, m[0]+i, m[1], 0)

win32gui.SetPixel(dc, m[0]+i, n[1], 0)

for i in range(n[1]-m[1]):

win32gui.SetPixel(dc, m[0], m[1]+i, 0)

win32gui.SetPixel(dc, n[0], m[1]+i, 0)

As you can see, the code will draw the rectangle, but the previous ones will remain until the screen updates.

The only solution I've came with is to take the pixel values i will paint before set them black, and redraw them every time, but this makes my code pretty slow. Is there an easy way t

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>