PyGTK is unmaintained and has been archived. It has been superseded by PyGObject. Links below might not work anymore and information below might be incorrect.
Checking if a DISPLAY is set
In PyGTK 2.8.x and earlier you could use the following code to determine if the DISPLAY is set or not:
That will not work in PyGTK 2.10 because the ImportError was made into a warning, so instead you'd have to make all warnings raise an exception in gtk module to be able to easily catch this error:
ChangeLog
Detailed information about each release
2.9.0
Remove gobject, pygobject is now a hard dependency
Set encoding in pango instead of gtk (328031)
Wrap gdk.Screen.get_rgba_colormap/get_rgbma_visual (328996, MarcoCabizza)
Remove private gtk wrappers (321476)
Add a bunch of missing wrappers (316881, JohnFinlay)
Add inout support in reverse wrappers (335964, GustavoCarneiro)
Update h2defs to allow whitespace before parenthesis (317124)
Make it possible to reimplement interfaces (334986, GustavoCarneiro)
Allow log_handler to be called when python is not initialized (334188, GustavoCarneiro)
Support for const object args (wollny@cbs.mpg.de, Gustavo)
Export pygtk tree model api (318021, GustavoCarneiro)
Allow overrides to be in base classes (327715, GustavoCarneiro)
Wrap a pango cairo font options acecssors (328108, RauliRuohonen)
Add GDK_PARENT_RELATIVE relative handling (320248, Johan, NikosKouremenos)
Improve pixbuf demo (327931, Ben Caradoc-Davies)
Set default markup accel marker to \x00 (329658, Johan, JohanSvedberg)
Set 1 as default argument to SpinButton.spin() (325452, SebastianRittau)
Wrap gdk.Drawable.gdk_draw_indexed_image (333431, Johan, HamishMoffatt)
Mark rowreference.free() as deprecated (309811, GustavoCarneiro)
Rename name of first keyword argument to pango.LayoutLine.index_to_x (316581, GustavoCarneiro, JohnFinlay)
Run reindent on all python code (325320, JohanDahlin)
Improve generictreemodel example (311459, StevenKennedy)
Wrap gdk.Pixbuf.rotate_simple (314164, KarelVervaeke)
Use in argument in gtk.TreeView.cell_get_size (JohnEhresman)
2.9.1
Allow gtk.TreeSortable.set_default_sort_func callback to be None (JohanDahlin, PatrickO'Brien)
Add API to unset the g_log handlers ((323786), JohanDahlin)
Allow the gtk module to be imported without DISPLAY ((316877), JohanDahlin)
Code cleanup and fixes considering Coverity reports (JohanDahlin)
Add codegen support for const-Object return type ((169204), GustavoCarneiro)
Add codgen support for unblocking threads around method calls (GustavoCarneiro)
Wrap gdk_event_handler_set (JohanDahlin)
Codegen reverse wrapper bug fix ((340162), YevgenMuntyan)
Wrap GdkRegion (JohnEhresman)
Add codegen support for ignore-type statement in override (JohanDahlin)
Add conditional support for gtk+ 2.10 API, especially printing (JohanDahlin, JohnFinlay, GustavoCarneiro)
Complete the support for gtk.Container virtual methods ((341641), GustavoCarneiro)
Fix misc. reference leaks (JohnFinlay, GustavoCarneiro)
Allow None parameter in pangocairo.CairoContext.set_font_options (JohnFinlay)
Complete the support for gtk.CellRenderer virtual methods ((339431), GustavoCarneiro)
IconView.set_cursor method params 'cell' and 'start_editing' made optional ((343039), RossBurton, JohnFinlay)
Wrap a few more gdk_cairo_* methods (JohnFinlay)
Add a 'selection' field to gdk.OWNER_CHANGE events (JohnFinlay)
Allow None in gtk.Entry.set_inner_border() (JohnFinlay)
gtk.Clipboard rich text methods (JohnFinlay)
Add gtk.MessageDialog.set_image() (JohnFinlay)
Wrap gtk_link_button_set_uri_hook() (JohnFinlay)
Allow None in gtk.Widget.input_shape_combine_mask() (JohnFinlay)
Allow gtk.LinkButton() constructor to optionally receive a label (JohnFinlay)
Allow None in gtk.Label.set_mnemonic_widget() (JohanDahlin)
Wrap a bunch of X11 specific gdk methods (GustavoCarneiro)
Add gtk.SizeGroup.get_widgets() (JohnFinlay)
Wrap gtk_style_lookup_color() (JohnFinlay)
Wrap a bunch of gtk treeview grid lines methods (JohnFinlay)
Better Drag and drop API support (JohnFinlay)
Add -I option to codegen (defs search path) (GustavoCarneiro)
2.9.2
Fix a codegen bug that prevent build of other extensions ((344845), GustavoCarneiro)
Builds with pycairo 1.1.6 ((344957), GustavoCarneiro)
gtk.TextBuffer rich text copy and serialization (JohnFinlay)
Correct Print Editor example (GustavoCarneiro)
2.9.3
Update to latest gtk+ 2.10 API changes ((345447), (345623), Newren, Peters)
Many more new gtk+ 2.10 APIs wrapped (JohnFinlay)
Wrap gtk_widget_class_find_style_property (JohnFinlay)
gtk.gdk.CairoContext.rectangle bug fix (GustavoCarneiro)
Update defs for atk 1.8 (JohnFinlay)
- Misc. module cleanups (Dahlin)
New pango APIs wrapped (JohnFinlay)
Fix refcount error in gtk.Clipboard ((343960), GustavoCarneiro, JohnFinlay)
Enable GDK X11-specific APIs available also with gtk+ 2.8 (GustavoCarneiro)
Lazy loading of the gtk.keysyms module (JohanDahlin)
2.9.4
Include John Finlay's PyGTK reference manual (JohanDahlin, JohnFinlay)
Setters and getters for GtkWidget.activate_signal ((331445), GustavoCarneiro)
GtkToolItemType setter/getter ((331355), GustavoCarneiro)
Code generator fixes (GustavoCarneiro, JohanDahlin, JohnFinlay, YevgenMuntyan)
Add more gtk+ 2.10 API ((337011), JohnFinlay, SebastianPölsterl)
Don't copy treeiters in callbacks ((347273), JohnFinlay, StefanoMaggiolo)
Provide full information for GtkTreeSelection.set_select_function ((340475) JohnFinlay, WouterBolsterlee)
Export less symbols and reduce the size of the libraries ((347825), RafaelEspíndola)
Allow negative values for GtkTreeModel.set/getitem ((311852), Baiju M)
Much improved interface/virtual method support (JohnFinlay)
Remove evil 100ms timeout timer ((348937), GustavoCarneiro)
2.9.5
Make it possible to build with GTK+ 2.10 ((350008), JosephSacco)
Make sure dir(gtk.keysyms) work again ((349892), JohanDahlin, JohnFinlay)
reloading the gtk module works again ((349026), JohanDahlin, AlexanderLarsson)
2.9.6
GtkTreePath can be converted from integers again ((350252), GustavoCarneiro, SebastienBacher)
Reduce exception abuse in code generator (GustavoCarneiro)
Documentation improvements (JohanDahlin, JohnFinlay)