Sep-06-2021, 09:14 PM
To enable
to do this change
The code you posted did not run, I tided it up and made it runnable
first.py
frame.label_1.Hide()
to work, label_1 needs to be an attribute of MyFrame
in first.py
to do this change
label_1
to self.label_1
The code you posted did not run, I tided it up and made it runnable
first.py
import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._create_controls() self._setup() self._create_sizers() self._create_binds() def on_button_1(self, event): print("Event handler 'on_button_1' not implemented!") event.Skip() def _create_controls(self): self.panel_1 = wx.Panel(self, wx.ID_ANY) self.label_1 = wx.StaticText( self.panel_1, label="Password:", style=wx.ALIGN_CENTER_HORIZONTAL ) self.button_1 = wx.Button(self.panel_1, label="hide") def _setup(self): self.SetSize((400, 300)) self.SetTitle("first") width, height = 80, 30 self.label_1.SetMinSize((width, height)) self.label_1.SetFont( wx.Font( 12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "", ) ) width, height = 80, 23 self.button_1.SetMinSize((width, height)) def _create_sizers(self): panel_sizer = wx.BoxSizer(wx.VERTICAL) self.panel_1.SetSizer(panel_sizer) # sizer_1.Add(label_1, 0, wx.LEFT, 50) # sizer_1 not defined # sizer_1.Add(sizer_4, 1, wx.EXPAND, 0) # sizer_1 & sizer_4 not defined # sizer_1.Add(button_1, 1, wx.LEFT, 50) # sizer_1 missing, button_1 not defined # sizer_1 = wx.BoxSizer(orient=wx.VERTICAL) panel_sizer.Add(self.label_1, 0, wx.LEFT, 50) panel_sizer.Add(self.button_1, 1, wx.LEFT, 50) self.panel_1.Layout() def _create_binds(self): # self.Bind(wx.EVT_BUTTON, self.hide, self.button_1) # do the bind directly on the button instance as follows self.button_1.Bind(wx.EVT_BUTTON, self.on_button_1) class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None) self.SetTopWindow(self.frame) self.frame.Show() return True if __name__ == "__main__": my_app = MyApp(False) my_app.MainLoop()second.py
import wx import first # class MyApp(fileHide.MyFrame): # fileHide not defined class MyFrame2(first.MyFrame): def __init__(self, parent): super().__init__(parent) def on_button_1(self, event): print("hide") self.button_1.Hide() if __name__ == "__main__": app = wx.App(False) frame = MyFrame2(None) frame.Show(True) frame.label_1.Hide() app.MainLoop()