Python Forum
How to clear the screen of glitched rectangles?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to clear the screen of glitched rectangles?
#1
I'm coding a program that captures a section of the screen as an image by drawing a rectangle with cursor, yet the process creates glitched rectangles. Is there a way to refresh the screen or maybe a completely different code that works? The dc.Clear() doesn't seem to clear the screen.

import wx 
import win32gui

app = wx.PySimpleApp() 
dc = wx.ScreenDC() 

dc.StartDrawingOnTop(None) 
dc.SetPen(wx.Pen('red', 2)) 
dc.SetBrush(wx.TRANSPARENT_BRUSH) 

int_x = win32gui.GetCursorPos()[0]
int_y = win32gui.GetCursorPos()[1]


while 1:
    dc.DrawRectangle(int_x,int_y,win32gui.GetCursorPos()[0]-int_x,win32gui.GetCursorPos()[1]-int_y)
    dc.Clear()
Reply
#2
The dc.clear() which should work but it's part of an endless while loop.

The 'jaggard' rectangles is is because the rectangle is constantly being drawn, then erased and the cycle repeated.
  • Remove the while
  • place the clear in a function
  • only call the clear function when you are actually ready to clear.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  clear screen with pycharm boris602 0 2,154 Dec-12-2019, 12:28 PM
Last Post: boris602
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,124 Feb-06-2019, 01:25 AM
Last Post: woooee
  PyCharm Clear Screen Larry 4 18,984 Feb-22-2018, 12:18 AM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020