getCursorHidden() behaviour


I am trying the following Python code hooked to a key to hide or display the mouse cursor.

def toggleMouseCursor(self):
    """shows or hides mouse cursor"""
    props = WindowProperties()
    hidden = props.getCursorHidden()
    print hidden
    props.setCursorHidden(not hidden)

It does not work, it hides the mouse cursor the first time (because it was visible by configuration), and
then the cursor never shows up again.
The print statement ALWAYS prints “False”
Although the following code works without a problem:

    def toggleMouseCursor(self):
        """shows or hides mouse cursor"""
        self.cursorHidden = not self.cursorHidden #keep track of this by hand
        props = WindowProperties()

Is there something wrong with the first snippet for what I want to achieve?


Have you tried calling “” to get the current window properties?

By which I mean something like the following:

props =
hidden = props.getCursorHidden()
# etc...

Thaumaturge is correct, but just to clarify on why your code doesn’t work:

This code creates a new, empty WindowProperties object. Calling getAnything on a WindowProperties object that does not specify any particular properties will either error or simply return some default settings. As Thaumaturge pointed out, you are interested in acquiring a WindowProperties object that specifies the current properties of the window, using

Then, you want to tell the window to update the setCursorHidden property, so your code would look somewhat like this:

def toggleMouseCursor(self):
    """shows or hides mouse cursor"""
    oldProps =
    hidden = oldProps.getCursorHidden()
    newProps = WindowProperties()
    newProps.setCursorHidden(not hidden)

Keep in mind that the WindowProperties object passed to requestProperties should be considered a ‘delta’ object; ie., it only specifies the properties that you want to change, instead of respecifying every single property.