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

  • Home
  • SEARCH
  • 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 9154615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:27:20+00:00 2026-06-17T12:27:20+00:00

I am new in pygtk. I am looking a way how to create custom

  • 0

I am new in pygtk. I am looking a way how to create custom widget which uses parent backgorund as its own background
something like this https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-prn1/31617_421363141269410_1875576801_n.jpg

How can I get parent bitmap and use it as its own bitmap?

class RoundRectPanel(gtk.DrawingArea, PanelBase):
    """
    Panel That represents
    """
    def __init__(self):
        super(ProximityPanel, self).__init__()

    def initialize(self):
        super(RoundRectPanel, self).initialize()

        self.set_size_request(340, 300)
        self.connect('expose-event', self.expose)

    def terminate(self):
        pass

    def rounded_rectangle(self, cr, x, y, w, h, r=20):
        #   A****BQ
        #  H      C
        #  *      *
        #  G      D
        #   F****E

        cr.move_to(x+r,y)                      # Move to A
        cr.line_to(x+w-r,y)                    # Straight line to B
        cr.curve_to(x+w,y,x+w,y,x+w,y+r)       # Curve to C, Control points are both at Q
        cr.line_to(x+w,y+h-r)                  # Move to D
        cr.curve_to(x+w,y+h,x+w,y+h,x+w-r,y+h) # Curve to E
        cr.line_to(x+r,y+h)                    # Line to F
        cr.curve_to(x,y+h,x,y+h,x,y+h-r)       # Curve to G
        cr.line_to(x,y+r)                      # Line to H
        cr.curve_to(x,y,x,y,x+r,y)             # Curve to A

    def expose(self, canvas, event):
        # Create cairo context
        cr = canvas.window.cairo_create()

        # TODO: 1. GET PARENT background
        # 2. set it as canvas background

        # 3. draw on it
        self.rounded_rectangle(cr, 0, 0, 340, 300)
        cr.stroke_preserve()
        cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
        cr.fill()
  • 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-17T12:27:21+00:00Added an answer on June 17, 2026 at 12:27 pm

    Currently found the workaround, which requires custom widget to communicate with his parent window (where the background image is drawn).
    CustomWidget requires from parent information about background image (filename and imge location on the window)

    class CustomWidget(gtk.DrawingArea):
    def __init__(self, parent):
        super(CustomWidget, self).__init__()
        self.set_size_request(340, 300)
        self._parent = parent
    
        self.connect('expose-event', self._expose_event)
    
    def _expose_event(self, widget, event):
        cr = widget.window.cairo_create()
    
        self.draw_context(cr, widget)
    
    def draw_context(self, cr, widget):
        ctx = cr
        x, y, width, height = widget.allocation
    
        # parent window should have file name that is used as a background
        pixbuf = gtk.gdk.pixbuf_new_from_file(self._parent.file)
        ctx.save()
        # copy particular image region where your custom widget is located
        ctx.set_source_pixbuf(pixbuf, (-x) + self._parent.image.allocation.x, (-y) + self._parent.image.allocation.y)
    
        # draw background for custom widget
        ctx.paint()
        ctx.restore()
    
        # now draw what ever you want
        self.rounded_rectangle(cr, 0, 0, width, height)
        cr.set_line_width(1.0)
        cr.set_source_color(gtk.gdk.color_parse('grey'))
        cr.stroke_preserve()
    
        gradient = cairo.LinearGradient(width/2, 0, width/2, height)
        gradient.add_color_stop_rgba(0.00, 1, 1, 1, 0.9)
        gradient.add_color_stop_rgba(1.00, 0.4, 0.4, 0.4, 0.5)
        cr.set_source(gradient)
        cr.fill()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I'm looking for a way to determine if the user switches virtual desktops under
I fill a form fields (in pygtk) from a class instance that contains its
According to the documentation , the create-new-window signal is called when a webkit is
New to matlab and I need some help. I need to create a .mat
New to jQuery, requesting assistance with something I'm having trouble figuring out. A cloned
I've searched on this, but nothing has what I'm looking for. http://www.mail-archive.com/pygtk@daa.com.au/msg10529.html -- Nobody
I have a created a new window using pygtk. I want the system to
New to linux and c++. I wante to create an application that only needs
I am writing a python/pygtk application that is adding some custom scripts (bash) in

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.