I am new to wxpython so please bare with me for this potential easy (silly) question: I have two panels in the frame, and I placed a button in one panel, and I need to draw a line in the other panel when the button is clicked. How can I achieve that?
This is the codes I have for now, which can draw a line in the same panel where the button is located. How to change the codes so the line show up in the gray panel? Thanks!
import wx
class myButton(wx.Button):
def __init__(self, parent, id, label, pos):
super().__init__(parent, id, label, pos)
self.Bind(wx.EVT_BUTTON, self.on_btn_click)
def on_btn_click(self, e):
print(f"Button is clicked.")
hline = wx.StaticLine(self.GetParent(),
-1,
style=wx.LI_HORIZONTAL,
pos=(20, 100),
size=wx.Size(50, 3))
hline.SetBackgroundColour('red')
class myPanelA(wx.Panel):
def __init__(self, parent, id=wx.ID_ANY,
pos=(0, 0),
size=wx.Size(200, 500)):
super(myPanelA, self).__init__(parent, id, pos, size)
btn = myButton(self, id=wx.ID_ANY, label="button", pos=(20, 200))
class myPanelB(wx.Panel):
def __init__(self, parent, id=wx.ID_ANY,
pos=(200, 0),
size=wx.Size(1500, 500)):
super(myPanelB, self).__init__(parent, id, pos, size)
class myFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.SetSize((1500, 500))
self.panel_a = myPanelA(self)
self.panel_a.SetBackgroundColour('blue')
self.panel_b = myPanelB(self)
self.panel_b.SetBackgroundColour('gray')
def main():
app =wx.App()
frame = myFrame(None)
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()