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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:55:47+00:00 2026-06-10T04:55:47+00:00

My goal is to make screenshot from window without displaying it. Code: All the

  • 0

My goal is to make screenshot from window without displaying it.

Code: All the Xvfb-things works with QT (example), but seems like I do not fully understand how to use it with GTK.

import gtk,webkit,gobject,sys,os,time
web=webkit.WebView()
url = 'http://google.com/'
web.open(url)
win=gtk.Window()
win.add(web)

silence_xvfb=True
display='1'
screen='0'
xvfb_timeout=3
pidfile = '/tmp/.X%s-lock' % display
redirect = '> /dev/null 2>&1'
if not silence_xvfb:
    redirect = ''
cmd = ' '.join(['Xvfb', ':'+display, '-screen', screen, '1600x1200x24', redirect])
os.system(cmd+' &')

start = time.time()
while(True):
    diff = time.time() - start
    if(diff > xvfb_timeout):
        raise SystemError("Timed-Out waiting for Xvfb to start - {0} sec".format(xvfb_timeout))
    if(os.path.isfile(pidfile)):
        break
    else:
        time.sleep(0.05)

os.putenv('DISPLAY', ':%s' % display)

def drawWindow(win):
    width, height = win.get_size()
    pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)

    screenshot = pixbuf.get_from_drawable(win.window, win.get_colormap(), 
                                          0, 0, 0, 0, width, height)

    screenshot.save('screenshot.png', 'png')
    print 'screenshot saved'

win.show_all()
gobject.timeout_add(5000, drawWindow, win)
gtk.main()
  • 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-10T04:55:49+00:00Added an answer on June 10, 2026 at 4:55 am

    All X11-based code (Qt, KDE, gtk, wxWindows, …) uses the DISPLAY variable to define which display to use. See the docs for details.

    You problem is that the variable is examined once per process at the time of the first X11 call (more or less).

    So in your case, you create a window and then you try to set the DISPLAY variable. X11 can’t move existing windows from one instance to another.

    What you need to do is split the code above into two processes. One starts Xvfb and sets the DISPLAY variable and the other renders the UI.

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

Sidebar

Related Questions

Goal is to make a dialog that appears on menu_key pressed, but it keeps
My goal is to make the Delete key (without any modifiers) move selected files
In my goal to make good code, I've validated my project in Visual Studio
I am new to repository pattern but i tried, my goal is to make
My goal is to make a layout that is 200% width and height, with
My goal here is to make a button. I want the text to sit
I'm re-writing alibrary with a mandate to make it totally allocation free. The goal
Goal: Produce an Excel document with information from 3 associated models that is similar
Goal: Make it possible to decorate class methods. When a class method gets decorated,
Goal: Make a decorator which can modify the scope that it is used 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.