I'm developing a GUI using wxPython (Boa Constructor IDE). My GUI has the following:

Rich text control
Start button
Stop Button

My requirement is that when I press the START button, numbers (1, 2, 3, etc.) should start printing in the text control; it should stop when I press the STOP button. Code and GUI are as shown. What changes do I need to make to meet my requirements?

import wx
import wx.richtext

def create(parent):
    return Frame3(parent)

[wxID_FRAME3, wxID_FRAME3BUTTON1, wxID_FRAME3BUTTON2, wxID_FRAME3PANEL1, 
 wxID_FRAME3RICHTEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(5)]

class Frame3(wx.Frame):
    def _init_ctrls(self, prnt):
    # generated method, don't edit
    wx.Frame.__init__(self, id=wxID_FRAME3, name='', parent=prnt,
          pos=wx.Point(579, 234), size=wx.Size(414, 492),
          style=wx.DEFAULT_FRAME_STYLE, title='Frame3')
    self.SetClientSize(wx.Size(406, 458))

    self.panel1 = wx.Panel(id=wxID_FRAME3PANEL1, name='panel1', parent=self,
          pos=wx.Point(0, 0), size=wx.Size(406, 458),
          style=wx.TAB_TRAVERSAL)

    self.richTextCtrl1 = wx.richtext.RichTextCtrl(id=wxID_FRAME3RICHTEXTCTRL1,
          parent=self.panel1, pos=wx.Point(96, 96), size=wx.Size(200, 100),
          style=wx.richtext.RE_MULTILINE, value=u'')
    self.richTextCtrl1.SetLabel(u'richText')

    self.button2 = wx.Button(id=wxID_FRAME3BUTTON2, label=u'STOP',
          name='button2', parent=self.panel1, pos=wx.Point(256, 280),
          size=wx.Size(75, 23), style=0)
    self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
          id=wxID_FRAME3BUTTON2)

    self.button1 = wx.Button(id=wxID_FRAME3BUTTON1, label=u'START',
          name='button1', parent=self.panel1, pos=wx.Point(88, 280),
          size=wx.Size(75, 23), style=0)
    self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
          id=wxID_FRAME3BUTTON1)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnButton1Button(self, event):  #START BUTTON
        event.Skip()

    def OnButton2Button(self, event):  #STOP BUTTON
        event.Skip()


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()

To get this to go without the GUI freezing up in some loop you have to use threading

@lardm ....Thanks lardm for the reply....
is there an alternative for threading...bcoz i dont watn to use threasds

Add a timer after adding the text control and the buttons.

Bind a function to the timer to increment a counter and to update the text control with the value of the counter.

When the start button is pressed, initialize the counter and start the timer.

When the stop button is pressed, stop the timer.

Let me know how this works for you.

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.