我有一个带有3个标签面板的应用。我目前正在同一个面板wx.CallAfter(self.running_log1.AppendText, line)
中将AppendText发送到wx.TextCtrl,但也希望将AppendText发送到另一个选项卡式面板RunningPane2 wx.CallAfter(RunningPane2.running_log2.AppendText, line)
中的wx.TextCtrl,我无法正常工作。我该怎么做,或者我可以完全取消RunningPane2类并从RunningPane1面板创建self.running_log2 = wx.TextCtrl
?
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(900, 700))
self.tabbed = wx.Notebook(self, -1, style=(wx.NB_TOP))
self.running1 = RunningPane1(self.tabbed, run_params)
self.running2 = RunningPane2(self.tabbed, run_params)
self.submissions = SubmissionPane(self.tabbed, self.running1, self.running2, run_params)
self.tabbed.AddPage(self.submissions, "Submit Job")
self.tabbed.AddPage(self.running1, "Running Jobs 1")
self.tabbed.AddPage(self.running2, "Running Jobs 2")
self.Show()
#---
class SubmissionPane(wx.Panel):
def __init__(self, parent, running_pane1, running_pane2, run_params):
wx.Panel.__init__(self, parent)
...............
class RunningPane1(wx.Panel):
def __init__(self, parent, run_params):
wx.Panel.__init__(self, parent, -1)
self.running_log1 = wx.TextCtrl(self, -1, pos=(5, 5), size=(875,605),
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
def StartWork(self, indir1, the_queue_pane, runningMode, showBox1, tvtitle):
..............
wx.CallAfter(self.running_log1.AppendText, line)
wx.CallAfter(RunningPane2.running_log2.AppendText, line)
..............
#---
class RunningPane2(wx.Panel):
def __init__(self, parent, run_params):
wx.Panel.__init__(self, parent, -1)
self.running_log2 = wx.TextCtrl(self, -1, pos=(5, 5), size=(875,605),
style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
self.Show()
答案 0 :(得分:1)
它不会以这种方式运作:RunningPane2.running_log2
。
您应该获得running_log2
的实例,您可以将MainWindow
实例传递到RunningPanel
,然后您可以从中获取running_log2
。
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
...........
self.running1 = RunningPane1(self.tabbed, self, run_params)
class RunningPane1(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent, -1)
..............
self.frame = frame
def StartWork(self, indir1, the_queue_pane, runningMode, showBox1, tvtitle):
..............
wx.CallAfter(self.running_log1.AppendText, line)
wx.CallAfter(self.frame.running2.running_log2.AppendText, line)