By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,806 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,806 IT Pros & Developers. It's quick & easy.

How to compare a wxPython class attribute inside of a function. :P

Jory R Ferrell
P: 62
The text_2 attribute is stored in a weird way apparently.
When I ask for input(self.text_2), I get the following:
<wx._controls.StaticText;proxy of <Swig Object of type 'wxStaticText *' at 0x2x37798>

Any idea how I can test the str value against another string? Basically I'm just trying to cycle between two different labels...but I can't figure this out. :P :/

Expand|Select|Wrap|Line Numbers
  1.     import wx
  2.     import time
  3.  
  4.  
  5.     class LeftPanel(wx.Panel):
  6.     def __init__(self, parent, id):
  7.     wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
  8.     self.text = parent.GetParent().rightPanel.text
  9.     self.text_2 = parent.GetParent().rightPanel.text_2
  10.     button1 = wx.Button(self, -1, 'Count', (10, 10))
  11.     button2 = wx.Button(self, -1, 'Countdown', (10, 60))
  12.     button3 = wx.Button(self, -1, 'Action', (10, 110))
  13.     self.Bind(wx.EVT_BUTTON, self.OnPlus, id=button1.GetId())
  14.     self.Bind(wx.EVT_BUTTON, self.OnMinus, id=button2.GetId())
  15.     self.Bind(wx.EVT_BUTTON, self.button_Pressed, id=button3.GetId())
  16.     self.timed_Out = 1
  17.  
  18.  
  19.     def OnPlus(self, event):
  20.     value = 1
  21.     for t in range(5000):
  22.     value = value + 1
  23.     time.sleep(1)
  24.     self.text.SetLabel(str(value))
  25.  
  26.     def OnMinus(self, event):
  27.     import math
  28.     value = 60
  29.     for t in range(value):
  30.     value = value - 1
  31.     time.sleep(1)
  32.     self.text.SetLabel(str(value/60) + ':' + str(value%60))
  33.  
  34.     self.timed_Out = 0
  35.     self.text_2.SetLabel(str('End o\'line.'))
  36.  
  37.     def button_Pressed(self, event):
  38.     if self.timed_Out == 1:
  39.     if self.text_2 == 'First':
  40.     self.text_2.SetLabel('Second')
  41.  
  42.     elif self.text_2 == 'Second':
  43.     self.text_2.SetLabel('First')
  44.  
  45.  
  46.  
  47.     class RightPanel(wx.Panel):
  48.     def __init__(self, parent, id):
  49.     wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
  50.     self.text = wx.StaticText(self, -1, '0', (10,60))
  51.     self.text_2 = wx.StaticText(self,-1,'First',(10, 120))
  52.  
  53.     class Communicate(wx.Frame):
  54.     def __init__(self, parent, id, title):
  55.     wx.Frame.__init__(self, parent, id, title, size=(600, 200))
  56.     panel = wx.Panel(self, -1)
  57.     self.rightPanel = RightPanel(panel, -1)
  58.     leftPanel = LeftPanel(panel, -1)
  59.     hbox = wx.BoxSizer()
  60.     hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 4)
  61.     hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)
  62.     panel.SetSizer(hbox)
  63.     self.Centre()
  64.     self.Show(True)
  65.  
  66.  
  67.  
  68.     app = wx.App()
  69.     Communicate(None, -1, 'widgets communicate')
  70.     app.MainLoop()
  71.  
Feb 4 '12 #1
Share this Question
Share on Google+
4 Replies

Jory R Ferrell
P: 62
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').
Feb 5 '12 #2

bvdet
Expert Mod 2.5K+
P: 2,851
Thanks for the update Jory. I am glad you could figure it out! I don't know much about wxPython.
Feb 7 '12 #3

Jory R Ferrell
P: 62
No problem. Some helped me on another site(I believe Stackoverflow.com) Btw...is it necessary to do the same thing(specify grabbing the value/text rather than the variable name) in tkinter/pyqt?
Feb 8 '12 #4

bvdet
Expert Mod 2.5K+
P: 2,851
@Jory R Ferrell
Tkinter is similar in that a variable object is created (Tkinter.StringVar(), Tkinter.IntVar(), etc.) and used to store a value. The value can be retrieved or changed by using the object's methods get() and set() respectively.
Feb 8 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.