0

So, essentially, I want something that can do this:

def onKeyPress(widget, event):
    if event.state & gtk.gdk.CONTROL_MASK and keyname == "a":
        Stop the loop somehow.

def doLoop(widget):
    while True:
        print "You're in"
        print "a loop"


mywindow = gtk.Window()
mywindow.connect("key_press_event", onKeyPress)
foo = gtk.Foo()
foo.connect("bar", doLoop)
mywindow.add(foo)

I don't know how to accomplish this, but I have tried using threading or different .py files, but I am kind of a beginner, so I want to know if there's an easier way.

user3299890
  • 23
  • 1
  • 7

1 Answers1

-1

Try having a boolean called KeyPressed that can be accessed from both the doLoop and onKeyPress functions. Then you can do this:

def onKeyPress(widget, event):
    if event.state & gtk.gdk.CONTROL_MASK and keyname == "a":
        KeyPressed = False

def doLoop(widget):
    while KeyPressed:
        print "You're in"
        print "a loop"


mywindow = gtk.Window()
mywindow.connect("key_press_event", onKeyPress)
foo = gtk.Foo()
foo.connect("bar", doLoop)
mywindow.add(foo)

KeyPressed would have to be set to True from the beginning.

austin-schick
  • 1,225
  • 7
  • 11