# Proof of concept for PyGTK+Pygame # Seo Sanghyeon import os, pygame, gtk import random def pygame_hack(widget): def callback(widget, *args): handle = widget.window.xid size = widget.size_request() os.environ['SDL_WINDOWID'] = str(handle) pygame.display.init() pygame.display.set_mode(size) widget.connect('map-event', callback) def fill_random(widget): screen = pygame.display.get_surface() r = random.randrange(255) g = random.randrange(255) b = random.randrange(255) screen.fill((r, g, b)) pygame.display.flip() def main(): win = gtk.Window() win.connect('destroy', gtk.main_quit) box = gtk.VBox() win.add(box) custom = gtk.DrawingArea() custom.set_size_request(300, 200) pygame_hack(custom) box.pack_start(custom) button = gtk.Button('Random fill') button.connect('clicked', fill_random) box.pack_start(button) win.show_all() gtk.main() if __name__ == '__main__': main()