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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:00:34+00:00 2026-05-31T11:00:34+00:00

I’m writing a wxPython app that needs to match the appearance of an existing

  • 0

I’m writing a wxPython app that needs to match the appearance of an existing Windows application.
I’m trying to put Static Text and Button controls on a panel with a gradient background. Here are the ways I’ve found, but I can’t help feeling that I’m missing something. How should I draw static text and custom controls and let the background show through?

  1. Somehow persuade native controls not to draw the background. This applies esp. to wxStaticText
  2. Turn on the global system option
    msw.window.no-clip-children to let the background show through?
  3. Pass in a repainting function that touches up the background of each
    control during its onPaint Handler

2 seems easiest but I wonder if it’s turned off for a reason. Are there any performance implications to turning on the no-clip-children globally? Is there any way to turn it on just for the windows I want?

edit: Sample code and screnshots

Sorry if this is starting to look like an answer in a question. I want to know if there is a right way to do this.

Screenshot of three static text controls.

#!/usr/bin/python
import wx

class GradientPanel(wx.Panel):
    def __init__(self,*args,**kwargs):
        wx.Panel.__init__(self,*args,**kwargs)
        self.Bind(wx.EVT_PAINT,lambda e: self.paintBackground())
        self.Bind(wx.EVT_ERASE_BACKGROUND,lambda e: None)

        self.t=wx.StaticText(self,pos=(30,20),label="wxStaticText. Looks bad on MSW")
        self.t2=MyStaticText(self,pos=(30,50), size=(300,25), label="MyStaticText. Needs ClipChildren turned off")
        self.t3=MyStaticTextWithCustomBackground(self,pos=(30,80),size=(300,25), label="This Control touches up its own background",paintBackgroundToDC=self.paintBackgroundToDC)

    def paintBackground(self):
        dc=wx.PaintDC(self)
        self.paintBackgroundToDC(self,dc)

    def paintBackgroundToDC(self,ofWindow,dc=None):
        r=self.GetScreenRect()
        r.SetTopLeft(ofWindow.ScreenToClient(r.GetTopLeft()))
        dc.GradientFillLinear(r,wx.Colour(240,240,240),wx.Colour(128,128,255),wx.SOUTH)

class MyStaticText(wx.Window):
    def __init__(self,parent,label,**kwargs):
        wx.Window.__init__(self,parent,**kwargs)
        self.label=label
        self.Bind(wx.EVT_PAINT,lambda e: self.repaint())
        self.Bind(wx.EVT_ERASE_BACKGROUND,lambda e: None)

    def repaint(self):
        self.repaintToDC(wx.PaintDC(self))

    def repaintToDC(self,dc):
        dc.DrawText(self.label,0,0)

class MyStaticTextWithCustomBackground(MyStaticText):
    def __init__(self,parent,label,paintBackgroundToDC=None,**kwargs):
        self.paintBackgroundToDC=paintBackgroundToDC
        MyStaticText.__init__(self,parent,label,**kwargs)

    def repaint(self):
        dc=wx.PaintDC(self)
        if self.paintBackgroundToDC:
            self.paintBackgroundToDC(self,dc)
        MyStaticText.repaintToDC(self,dc)

if __name__ == "__main__":
    #wx.SystemOptions.SetOptionInt('msw.window.no-clip-children',1)
    app=wx.PySimpleApp()
    frame=wx.Frame(None,title="Transparent Controls")
    panel=GradientPanel(frame)
    frame.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-31T11:00:36+00:00Added an answer on May 31, 2026 at 11:00 am

    I ran into this exact problem the other day: how to display static text with a transparent background using wxPython. Here’s what I came up with:

    class TransparentText(wx.StaticText):
      def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=wx.TRANSPARENT_WINDOW, name='transparenttext'):
        wx.StaticText.__init__(self, parent, id, label, pos, size, style, name)
    
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None)
        self.Bind(wx.EVT_SIZE, self.on_size)
    
      def on_paint(self, event):
        bdc = wx.PaintDC(self)
        dc = wx.GCDC(bdc)
    
        font_face = self.GetFont()
        font_color = self.GetForegroundColour()
    
        dc.SetFont(font_face)
        dc.SetTextForeground(font_color)
        dc.DrawText(self.GetLabel(), 0, 0)
    
      def on_size(self, event):
        self.Refresh()
        event.Skip()
    

    A couple of key things:

    1. The window style should be wx.TRANSPARENT_WINDOW (all controls are windows in wxwidgets)
    2. Use GCDC instead of a normal DC, because the former has much better transparency support

    I have noticed occasional problems where the parent panel’s background does not get invalidated when the content of the TransparentText control gets updated. It’s not consistent, and it usually works well.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.