Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Paul Finch
5,484 PointsProblems importing modules.
I have a module that creates a graphical main menu called menu.py. This module has an import that imports a module called vehicle.py which is a graphical sub menu. To be able to exit out of the sub menu back to the main menu I have tried to import the menu.py module into the vehicle.py module but this does not work as the import fails. The gui's are wxPython classes and are called using the following in the menu.py
from vehicles import *
def clicked_vehicle(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()
To return I call
from menu import * #**This import does not work**
def clicked_main_menu(self, event):
self.GetParent() # This assigns parent frame to frame.
self.Close() # This then closes frame removing the main menu.
frame = Menu(None)
frame.Centre()
frame.Show()
I am unable to import menu.py into this module so Menu(None) is unknown value. If I import menu.py I get an unable to import error.
I have tried leaving the main menu open and this does work but does not look to good. Also tried hiding and showing the main menu but couldn't get that to work either.
Anyone have any ideas as Im only learning.
2 Answers
Julian Garcia
18,380 PointsYou could try adding a point before menu:
from .menu import *
Paul Finch
5,484 PointsNo that doesn't work got Attempted relative import in non-package.