Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing an application using Python and GTK3. This application will open instances of other applications, such as GEdit. Now, I'd also want my application to be able to focus each of those instances. My application is specifically targeted at Unity.

How do I do this?

share|improve this question
could be very helpful. combine the two -… ...… – RobotHumans Mar 14 '12 at 4:28
up vote 1 down vote accepted

Ok, so it turns out that actually switching windows is very easy.

#!/usr/bin/env python

# This code will focus the window with integer id 67108870
# Tips: you can get that with xwininfo -int

# wnck is used for window management
import wnck

# time is needed because wnck requires it
import time

# Get information about windows, workspaces, etc from the X server

# Get a reference to the window we want to focus
# by providing an integer xid
the_win = wnck.window_get(67108870)

# activate the window, providing an int timestamp

I'll improve on this answer as I learn.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.