不同的wx在不同的模块中创建菜单

时间:2016-07-08 18:41:12

标签: python wxpython wxwidgets wxformbuilder

我在自己的模块中构建了多个菜单。 menu.py模块导入子菜单,然后创建一个显示子菜单的实例。

我的问题是从子菜单返回主菜单(menu.py)。 这是主菜单代码。 menu.py

from gui import *
import wx
from tools import Tools
from vehicles import VehicleMainMenu
from ladders import LadderMainMenu


class TopMenu(MainMenu):
    def __init__(self, parent):
        MainMenu.__init__(self, parent)

    def close_bigbutton_click(self, event):
        exit(0)

    def tools_button_click( self, event ):
        self.GetParent()  # This assigns parent frame to frame.
        self.Close()  # This then closes frame removing the main menu.
        frame = Tools(None)
        frame.Centre()
        frame.Show()

    def vehicle_button_click( self, event ):
        self.GetParent()  # This assigns parent frame to frame.
        self.Close()  # This then closes frame removing the main menu.
        frame = VehicleMainMenu(None)
        frame.Centre()
        frame.Show()

    def ladder_button_click( self, event ):
        self.GetParent()  # This assigns parent frame to frame.
        self.Close()  # This then closes frame removing the main menu.
        frame = LadderMainMenu(None)
        frame.Centre()
        frame.Show()

我最初的想法是将主模块导入每个子模块,并在每个子菜单模块中执行以下操作

vehicles.py

class VehicleMainMenu(VehicleMenu):
def __init__(self, parent):
    VehicleMenu.__init__(self, parent)


    def veiw_vehicle_click(self, event):
        self.GetParent()  # This assigns parent frame to frame.
        self.Close()  # This then closes frame removing the main menu.
        frame = VehicleListGrid(None)
        frame.Centre()
        frame.Show(

    #This was the code to return to the main menu (main.py)
    def back_click( self, event ):
        self.GetParent()  # This assigns parent frame to frame.
        self.Close()  # This then closes frame removing the main menu.
        frame = TopMenu(None)
        frame.Centre()
        frame.Show()

我无法将菜单(menu.py)导入其他子菜单模块,因为这会引发错误。我尝试了各种许可,但我无法返回主菜单。

请帮忙吗?

1 个答案:

答案 0 :(得分:0)

通过将menu.py模块

导入子菜单模型来解决问题
import menu

然后使用

def back_click( self, event ):
    self.GetParent()  # This assigns parent frame to frame.
    self.Close()  # This then closes frame removing the main menu.
    frame = menu.TopMenu(None) #never used menu. in previous attempts
    frame.Centre()
    frame.Show()

返回menu.py模块中的主菜单(TopMenu)。