Я пытаюсь передать значения между классами в wx Python и, похоже, работает (переданное значение выводится на консоль), но я не знаю, почему bottomLabel
не меняет своего значения - аргументы передаются правильно, но метод changeLabel()
не обновляет метку.
Вот код:
import wx
class TopPanel(wx.Panel):
def __init__(self, parent):
Main.btm = BottomPanel(parent=parent)
wx.Panel.__init__(self, parent=parent)
self.label = wx.StaticText(self, label='Choose your animal:', pos=(10, 30))
animals = ["dog", "cat", "mouse"]
self.combobox = wx.ComboBox(self, choices=animals, pos=(10, 50))
self.label2 = wx.StaticText(self, label="", pos=(10, 80))
self.combobox.Bind(wx.EVT_COMBOBOX, self.onCombo)
def onCombo(self, event):
comboValue = self.combobox.GetValue()
self.label2.SetLabel("Chosen animal: " + comboValue)
Main.animal = comboValue
Main.btm.changeLabel(event, comboValue)
class BottomPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.SetBackgroundColour("grey")
self.bottomLabel = wx.StaticText(self, label="MyBottomLabel", pos=(10, 50))
def changeLabel(self, event, passedText):
self.bottomLabel.SetLabel(passedText)
print(passedText)
class Main(wx.Frame):
btm=None
animal = ""
def __init__(self):
wx.Frame.__init__(self, parent=None, title="Generator", size=(500, 500))
splitter = wx.SplitterWindow(self)
top = TopPanel(splitter)
bottom = BottomPanel(splitter)
splitter.SplitHorizontally(top, bottom)
splitter.SetMinimumPaneSize(250)
if __name__ == "__main__":
app = wx.App(False)
frame = Main()
frame.Show()
app.MainLoop()
Я новичок в OOP в Python, извините, если код не самый элегантный.