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 7021351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:26:18+00:00 2026-05-27T23:26:18+00:00

i am trying to Refresh() a panel which uses the wx.ColourDialog. Once I refresh

  • 0

i am trying to Refresh() a panel which uses the wx.ColourDialog. Once I refresh the panel once, it is unable to refresh again. Try the following to see the problem in action.

By clicking the button, it will ask you what color you would like to change the rectangle to. Once you press OK, it should change the rectangles color. It will not work it will not change the rectangle.

import wx 
xcolor_of_font_dia=(0,0,0)
class MyFrame(wx.Frame): 
    """a frame with a panel"""
    def __init__(self, parent=None, id=wx.ID_ANY, title=None):
        global xcolor_of_font_dia
        global dc
        wx.Frame.__init__(self, parent, wx.ID_ANY, title) 
        self.panel = wx.Panel(self, size=(350, 200)) 
        self.panel.Bind(wx.EVT_PAINT, self.on_paint)
        self.button2 = wx.Button(self.panel, id=wx.ID_ANY, label='Button2',pos=(8, 38), size=(175, 28))
        self.button2.Bind(wx.EVT_BUTTON, self.onColorDlg)
        self.Fit() 
    def onColorDlg(self, event):
        global xcolor_of_font_dia
        global dc
        """
        This is mostly from the wxPython Demo!
        """
        dlg = wx.ColourDialog(self)

        # Ensure the full colour dialog is displayed, 
        # not the abbreviated version.
        dlg.GetColourData().SetChooseFull(True)

        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            print 'You selected: %s\n' % str(data.GetColour().Get())
            xcolor_of_font_dia='#%02x%02x%02x' % data.GetColour().Get()
        dlg.Destroy()
        self.panel.Refresh()
    def on_paint(self, event):
        global xcolor_of_font_dia
        global dc
        dc = wx.PaintDC(self.panel)
        dc.SetPen(wx.Pen(xcolor_of_font_dia, 1))
        rect = wx.Rect(50, 50, 100, 100) 
        dc.DrawRoundedRectangleRect(rect, 8)


# test it ...
app = wx.PySimpleApp() 
frame1 = MyFrame(title='rounded-rectangle & circle') 
frame1.Center() 
frame1.Show() 
app.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-05-27T23:26:19+00:00Added an answer on May 27, 2026 at 11:26 pm

    I cleaned your code a bit. Basically your globals were producing some problems as you were creating (and deleting) different dc instances after every size event.
    You should not use globals if it is not strictly necessary (rarely is).

    This works:

    import wx 
    
    
    class MyFrame(wx.Frame): 
        """a frame with a panel"""
        def __init__(self, parent=None, id=wx.ID_ANY, title=None):
            wx.Frame.__init__(self, parent, wx.ID_ANY, title) 
            self.xcolor = (0, 0, 0)
            self.panel = wx.Panel(self, size=(350, 200)) 
            self.panel.Bind(wx.EVT_PAINT, self.on_paint)
            self.button2 = wx.Button(self.panel, id=wx.ID_ANY, label='Button2',
                                                 pos=(8, 38), size=(175, 28))
            self.button2.Bind(wx.EVT_BUTTON, self.onColorDlg)
    
            self.Fit() 
    
        def onColorDlg(self, event):
            """
            This is mostly from the wxPython Demo!
            """
            dlg = wx.ColourDialog(None)
            dlg.GetColourData().SetChooseFull(True)
    
            if dlg.ShowModal() == wx.ID_OK:
                data = dlg.GetColourData()
                self.xcolor = data.GetColour().Get()
                print 'You selected: %s\n' % str(self.xcolor)
    
            dlg.Destroy()
            self.panel.Refresh()
    
        def on_paint(self, event):
            dc = wx.PaintDC(self.panel)
            dc.SetPen(wx.Pen(self.xcolor, 2))
            rect = wx.Rect(50, 50, 100, 100) 
            dc.DrawRoundedRectangleRect(rect, 8)
    
    
    # test it ...
    app = wx.PySimpleApp() 
    frame1 = MyFrame(title='rounded-rectangle & circle') 
    frame1.Center() 
    frame1.Show() 
    app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the following code to fire once on page load/refresh
I'm trying to refresh update panel via Javascript: __doPostBack(<%=upMyPanel.ClientID %>, ); But somehow its
I'm trying to refresh a div from Javascript at each loop and see 1,
I'm trying to refresh a page without sending POST from the previous time. I've
I am trying to refresh a UITableView with new cells every 30 seconds. My
I am trying to use periodic refresh(ajax)/polling on my site by XMLHttp(XHR) to check
I'm having a heck of a time trying to get a gridview to refresh
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying make a static text which if too long for the sizer, will
I am having a problem when trying to login.. below is my code for

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.