当前位置:   article > 正文

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

python画空心矩形

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

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号