Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:08:52+00:00 2026-06-03T14:08:52+00:00

I would like to draw some simple drawings (lines, circles, etc.) on panel in

  • 0

I would like to draw some simple drawings (lines, circles, etc.) on panel in wxpython. I modified an example code I found somewhere. It works fine, but just until I minimize the window or switch to another window and back. Then it starts repainting in infinite loop.

Should this even happen? If not, is there any way to prevent the infinite loop?

One solution I found was using wx.Timer, but it just caused same loop with adjustable intervals.

import math

import wx

class DrawPanel(wx.Frame):

    def __init__(self,parent):
        wx.Frame.__init__(self,parent,title='Drawing on panel')
        self.Bind(wx.EVT_PAINT,self.OnDraw)

    def OnDraw(self,event=None):
        self.dc = wx.PaintDC(self)
        self.dc.Clear()
        self.dc.SetPen(wx.Pen(wx.BLACK,1.5))
        i0 = 1
        for i in range(2,1000,1):
            i = i/10.0
            self.dc.DrawLine(i0,200*math.sin(i0/10)+200,
                        i,200*math.sin(i/10)+200)
            i0 = i

if __name__ == '__main__':
    aplication = wx.App()
    ram = DrawPanel(parent=None)
    ram.Show()
    aplication.MainLoop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:08:55+00:00Added an answer on June 3, 2026 at 2:08 pm

    In the function OnDraw create local variable dc instead of using attribute (dc instead of self.dc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to draw some shapes on a JPanel by overriding paintComponent .
I want to draw some listview items disabled and would like to mimic the
I would like to draw lines (of arbitrary position and length) onto a surface
I would like to write some simple Mario-like game from scratch using language C.
I would like to do some simple layout math. I remember the syntax below
I would like to draw a simple circle and move it to the defined
I have some (fairly large) UIButtons. Instead of text, I would like to draw
I would like to draw a chart in OpenGL similar to the donut graph
I would like to draw a line or bar graph using HTML5 canvas. I
I would like to draw a box using SAS/GRAPH with a color gradient (say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.