我是 wxPython 的新手,并且研究过类似的问题,但无法具体找到我的问题的答案。我正在创建两个带有分离器的面板。每个面板都有许多小部件。我想在一个面板中有一个小部件来控制另一个面板的某些属性,反之亦然)
在示例中,我试图RightPanel
从 中的按钮更改背景LeftPanel
。我显然做错了,因为我得到一个错误:
TypeError: init () 正好接受 2 个参数(1 个给定)
代码:
import wx
import wx.grid as gridlib
import pyodbc
class RightPanel(wx.Panel):
""""""
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
grid = gridlib.Grid(self)
grid.CreateGrid(5,5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(grid, 0, wx.EXPAND)
self.SetSizer(sizer)
class LeftPanel(wx.Panel):
""""""
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
self.create_controls()
self.SetBackgroundColour("light green")
def create_controls(self):
self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.v_sizer = wx.BoxSizer(wx.VERTICAL)
self.button = wx.Button(self, label="Press me!")
self.button.Bind(wx.EVT_BUTTON, self.on_button_pressed)
self.v_sizer.Add(self.button, 0)
self.v_sizer.Add(self.h_sizer, 0, wx.EXPAND)
self.SetSizer(self.v_sizer)
def on_button_pressed(Panel,event):
RightPanel().SetBackgroundColour("light blue")
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "DB Viewer",size=(350, 250))
splitter = wx.SplitterWindow(self)
leftP = LeftPanel(splitter)
rightP = RightPanel(splitter)
splitter.SplitVertically(leftP, rightP)
splitter.SetMinimumPaneSize(20)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(splitter, 1, wx.EXPAND)
self.SetSizer(sizer)
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
非常感谢任何帮助。问候