Hi, all, I want to separate different widgets creation for my application so that I can manipulate it more easily. For example, I want to create a menu called File, so I create it in a separate file called menu_file.py, I also create a menu_bar.py, a main_frame.py and a main_panel.py like bellow, but it does’t work. I checked all the single components with ChatGPT, but no errors appeared, Can anyone give me some clues?
main_frame.py
import wx
from menu_bar import MenuBar
from main_panel import MainPanel
class MainFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(MainFrame, self).__init__(*args, **kwargs)
self.menu_bar = MenuBar(self)
self.main_panel = MainPanel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.menu_bar, 0, wx.EXPAND)
sizer.Add(self.main_panel, 1, wx.EXPAND)
self.SetSizer(sizer)
self.SetMenuBar(self.menu_bar)
if __name__ == '__main__':
app = wx.App()
frame = MainFrame(parent=None, title="SimpleApp", size=(800, 600))
frame.Show()
app.MainLoop()
main_panel.py
import wx
class MainPanel(wx.Panel):
def __init__(self, parent):
super(MainPanel, self).__init__(parent)
self.SetBackgroundColour(wx.Colour(255, 255, 255)) # Set panel background
menu_bar.py
import wx
from menu_file import FileMenu
class MenuBar(wx.MenuBar):
def __init__(self, parent):
super(MenuBar, self).__init__()
file_menu = FileMenu(parent)
self.Append(file_menu, "File")
menu_file.py
import wx
class FileMenu(wx.Menu):
def __init__(self, parent):
super(FileMenu, self).__init__()
self.Append(wx.ID_OPEN, 'Open')
self.Append(wx.ID_SAVE, 'Save')