#!/usr/bin/env python

import gtk

class ContextMenu(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self)
        self.set_title("Context Menu")
        self.set_default_size(200, 200)
        self.connect("destroy", gtk.main_quit)

        eventbox = gtk.EventBox()
        eventbox.connect("button-release-event", self.on_menu_display)
        self.add(eventbox)

        label = gtk.Label("Right-click on this window")
        eventbox.add(label)

        self.menu = gtk.Menu()

        menuitem1 = gtk.MenuItem("MenuItem 1")
        self.menu.append(menuitem1)
        menuitem2 = gtk.MenuItem("MenuItem 2")
        self.menu.append(menuitem2)
        menuitem3 = gtk.MenuItem("MenuItem 3")
        self.menu.append(menuitem3)

    def on_menu_display(self, widget, event):
        if event.button == 3:
            self.menu.popup(None, None, None, event.button, event.time)
            self.menu.show_all()

window = ContextMenu()
window.show_all()

gtk.main()
