QT window closes immediately

Martin Caum herrxandor at gmail.com
Mon Nov 15 02:04:38 CET 2010

I am attempting to open a window on mouse activity which works, but
the window fails to stay open.
I set it to terminate when the escape key is pressed even when the
program is not currently selected. This works fine. Originally I had
it create the window only with a right click, but when I noticed the
window closed immediately I set it to any mouse activity for easier
debugging. My script is as follows:
import pythoncom, pyHook
import sys
import win32api
from PyQt4 import QtGui, QtCore

class WindowObject(QtGui.QWidget):
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)
		self.resize(50, 250)

def OnKeyboardEvent(event):
	if event.KeyID == 27:
	return 1

def OnMouseEvent(event):
	x = event.Position[0]
	y = event.Position[1]
	createWindow(x, y)
	return 1

def createWindow(x, y):
	menu = WindowObject()
	menu.move(x, y)

hm = pyHook.HookManager()
hm.MouseAll = OnMouseEvent
hm.KeyDown = OnKeyboardEvent

app = QtGui.QApplication(sys.argv)
I'm fairly certain that this is due to my lack of understanding in the
PumpMessages command and the HookManager. Any advice?

More information about the Python-list mailing list