Sep-06-2021, 04:13 PM
This is something simple that I cannot get my head around!
In one module I set up a wx gui, that has some buttons which are bound to events, and some like wxlabel which are not.
this is imported into a second module, within which the attributes for the widgets are manipulated eg "button_1.Hide()" This works fine for the widgets that are bound to events, but not if that is not the case eg label_1.Hide(). I am pretty new at this and have tried everything to acheive this unsuccessfully
Thanks in advance
In one module I set up a wx gui, that has some buttons which are bound to events, and some like wxlabel which are not.
this is imported into a second module, within which the attributes for the widgets are manipulated eg "button_1.Hide()" This works fine for the widgets that are bound to events, but not if that is not the case eg label_1.Hide(). I am pretty new at this and have tried everything to acheive this unsuccessfully
#first module first.py import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.SetSize((400, 300)) self.SetTitle("first") self.panel_1 = wx.Panel(self, wx.ID_ANY) label_1 = wx.StaticText(self.panel_1, wx.ID_ANY, "Password:", style=wx.ALIGN_CENTER_HORIZONTAL) label_1.SetMinSize((80, 30)) label_1.SetFont(wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, 0, "")) sizer_1.Add(label_1, 0, wx.LEFT, 50) sizer_1.Add(sizer_4, 1, wx.EXPAND, 0) self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, "hide") self.button_1.SetMinSize((80, 23)) sizer_1.Add(button_1, 1, wx.LEFT, 50) self.Layout() self.Bind(wx.EVT_BUTTON, self.hide, self.button_1) def hide(self, event): # wxGlade: MyFrame.<event_handler> print("Event handler 'hide' not implemented!") event.Skip() class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, wx.ID_ANY, "") self.SetTopWindow(self.frame) self.frame.Show() return True # end of class MyApp def __del__( self ): pass --------------------------------------------------------------
# second module "second.py" import wx import first class MyApp(fileHide.MyFrame): def __init__(self,parent): first.MyFrame. __init__(self,parent) def hide(self, event): print('hide') self.button_1.Hide() app = wx.App(False) frame = MyApp(None) frame.Show(True) frame.label_1.Hide() # error no frame has no attribute label_1 .... app.MainLoop()So I want to access label_1 in the second module, how can I do this?
Thanks in advance