Hello,
I want the computer to show a number, wait, increase the number and then show it again. Some simple print commands. If I press a key the program should stop. And if I press it again the program should play again.
I've tried this code:
My problem is, it isn't working. Only if 10 numbers have been showed I'm able to press some keys. I would like to have these 2 processes working parallel to each other. The process to wait until I press a key and the process to increase the numbers.
Of course it's only an abstract example. Think of an EGO-Shooter and you're doing nothing. Everything else is happening but you don't take any actions.
import wx
import time
class PressedKey(wx.Panel):
def __init__(self, parent3):
wx.Panel.__init__(self, parent3, -1, style=0)
self.Bind(wx.EVT_CHAR, self.LogKeyEvent)
self.SetFocus()
self.Key_Enter = 13
self.PressedKeyCode = 0
self.Stop = 'NO'
def do_action(self):
if self.PressedKeyCode == self.Key_Enter:
self.Stop = 'YES'
elif self.PressedKeyCode == self.Key_a:
self.Stop = 'NO'
def LogKeyEvent(self, evt):
self.PressedKeyCode = evt.GetKeyCode()
self.do_action()
class Core:
def __init__(self):
self.counter = 0
def run(self):
self.counter += 1
time.sleep(1)
print self.counter
class MyApp(wx.App):
def OnInit(self):
frame3 = wx.Frame(None, -1, "Keep Focus", pos=(0, 0), size=(300, 250))
c = Core()
pk = PressedKey(frame3)
frame3.Show(True)
while c.counter < 10:
if pk.Stop == 'NO':
c.run()
return True
app = MyApp(0)
app.MainLoop()