It starts off fine, after starting the countdown function and pressing the Action button, it causes the program to freeze.

import wx
import time
 
 
class LeftPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
        self.text = parent.GetParent().rightPanel.text
        self.text_2 = parent.GetParent().rightPanel.text_2
        button1 = wx.Button(self, -1, 'Count', (10, 10))
        button2 = wx.Button(self, -1, 'Countdown', (10, 60))
        button3 = wx.Button(self, -1, 'Action', (10, 110))
        self.Bind(wx.EVT_BUTTON, self.OnPlus, id=button1.GetId())
        self.Bind(wx.EVT_BUTTON, self.OnMinus, id=button2.GetId())
        self.Bind(wx.EVT_BUTTON, self.button_Pressed, id=button3.GetId())
        self.timed_Out = 1     
 
 
    def OnPlus(self, event):
        value = 1
        for t in range(5000):
            value = value + 1
            time.sleep(1)
            self.text.SetLabel(str(value))
 
    def OnMinus(self, event):
        import math
        value = 60
        for t in range(value):
            value = value - 1
            time.sleep(1)
            self.text.SetLabel(str(value/60) + ':' + str(value%60))
 
        self.timed_Out = 0
        self.text_2.SetLabel(str('End o\'line.'))
 
    def button_Pressed(self, event):
        if self.timed_Out == 1:
            if self.text_2 == 'First':
                self.text_2.SetLabel('Second')
 
            elif self.text_2 == 'Second':
                 self.text_2.SetLabel('First')
 
 
 
class RightPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
        self.text = wx.StaticText(self, -1, '0', (10,60))
        self.text_2 = wx.StaticText(self,-1,'First',(10, 120))
 
class Communicate(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 200))
        panel = wx.Panel(self, -1)
        self.rightPanel = RightPanel(panel, -1)
        leftPanel = LeftPanel(panel, -1)
        hbox = wx.BoxSizer()
        hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 4)
        hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)
        panel.SetSizer(hbox)
        self.Centre()
        self.Show(True)
 
 
 
app = wx.App()
Communicate(None, -1, 'widgets communicate')
app.MainLoop()

In the OnPlus function, the program will sleep for 1*5000 seconds which is about 1 1/2 hours. In the OnMinus function also, you add/subtract one from value but it has no meaning i.e is not displayed. You should test each function individually as you create it, otherwise you will be stuck with a large block of code and no idea where the error is. Finally, please read the Python Style Guide concerning naming conventions. It makes code easier to read and understand.

In the OnPlus function, the program will sleep for 1*5000 seconds which is about 1 1/2 hours. In the OnMinus function also, you add/subtract one from value but it has no meaning i.e is not displayed. You should test each function individually as you create it, otherwise you will be stuck with a large block of code and no idea where the error is. Finally, please read the Python Style Guide concerning naming conventions. It makes code easier to read and understand.

I can't figure out why my second label is not updating. Again, I haven't even started
the loop and I can't update the second label. :(

I just tried to get a look at the value assigned to self.text_2 in memory. I didn't realize that the value apparently isn't stored as a normal type (int or str)... :/

The readout:

<wx._controls.StaticText;proxy of <Swig Object of type 'wxStaticText *' at 0x2x37798>

Is there a way to turn this into a manageable type?

Nevermind. If you want to compare the text value assigned to the attribute instead of the attribute name itself, you have to specify that: self.text_2.GetLabelText()
This allows you to grab the value assigned, otherwise you make a reference to the actual variable name 'text_2' which is static text and does not equal the string value assigned to it, even if they seem to be the same word or number, just like str(5) is not equal to int('5').

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.