Python/PySide ImportError -
so have started larn python , toolkit pyside have ran problem can't find solution to, here error code:
traceback (most recent phone call last): file "c:\users\callum\workspace\application\main.py", line 1, in <module> ui.window import window file "c:\users\callum\workspace\application\ui\window.py", line 4, in <module> ui.menubar import menubar file "c:\users\callum\workspace\application\ui\menubar.py", line 3, in <module> ui.window import window importerror: cannot import name 'window' and here code:
main.py:
from ui.window import window wind = window() wind.create() window.py:
import sys pyside.qtcore import * pyside.qtgui import * ui.menubar import menubar class window: title = "callum" minwidth = 980 minheight = 640 app = none win = none def create(self): self.app = qapplication(sys.argv) self.win = qmainwindow() self.win.setwindowtitle(self.title) self.win.setminimumsize(self.minwidth, self.minheight) mb = menubar() mb.create() self.win.show() sys.exit(self.app.exec_()) menubar.py:
from pyside.qtcore import * pyside.qtgui import * ui.window import window class menubar: def create(self): wind = window() menu = wind.menubar() filemenu = menu.addmenu("file") filemenu.addaction("exit", exit)
if @ traceback, see that:
main.py importsui.window then:
window.py importsui.menubar and then:
menubar.py importsui.window and we're infinite loop of imports, window importing menubar importing window importing menubar ... etc, etc. except of course of study python prevents situation happening raising error instead.
however, there other problems how application structured. in particular, menubar.create method creates new instance of window, adds menu items it, , throws results away. should instead do, pass existing instance of window menubar.create argument, this:
from pyside.qtcore import * pyside.qtgui import * # remove follwing import, not needed # ui.window import window class menubar: def create(self, wind): # don't create new instance # wind = window() menu = wind.menubar() filemenu = menu.addmenu("file") filemenu.addaction("exit", exit) and in window.py, this:
self.win = qmainwindow() ... mb = menubar() mb.create(self.win) python pyside
No comments:
Post a Comment