Hi,
this is my first post here at Daniweb. Seems like an active and friendly environment.
I have very limited experience with programming in general, and even more so with GUI programming.
As the title suggests, I want to stop a while loop by the use of buttons.
When I press the start button, the program prints out "True" on the command window (I'm using windows). I am unable to press the stop button, the program just continues to print "True". I have to abort it to be able to stop.
How can I fix this?
Also, how can I print "True" on the panel instead of command window?
Thanks
import wx
class whileLoop(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'whileLoop', size=(300,200))
panel = wx.Panel(self)
startButton = wx.Button(panel, label="start", pos=(10,10), size=(40,30))
self.Bind(wx.EVT_BUTTON, self.startLoop, startButton)
stopButton = wx.Button(panel, label="stop", pos=(60,10), size=(40,30))
self.Bind(wx.EVT_BUTTON, self.stopLoop, stopButton)
def startLoop(self,event):
global flag
flag = True
while flag:
if flag == False:
break
else:
print "True"
def stopLoop(self,event):
global flag
flag = False
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = whileLoop(parent=None,id=-1)
frame.Show()
app.MainLoop()