我正在尝试将 python 脚本编写到 matplotlib 之类的应用程序中。我需要一个函数调用来显示 Qt 主窗口。我该怎么做呢?
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.numbers = 4
...
app = QtGui.QApplication(sys.argv)
dmw = DesignerMainWindow()
dmw.show()
sys.exit(app.exec_()) #this works, but pops the window right away
我希望能够在我希望的时候调用窗口。(像这样的东西)
def newWin():
app = QtGui.QApplication(sys.argv)
dwm = MainWindow()
sys.exit(app.exec_())
return dwn
a = newWin() # application is created now
a.numbers = 10 # do something
a.show() # should pop me the window now
编辑:感谢 jadkik94粘贴解决方案
class App(QtGui.QApplication):
def __init__(self, args):
QtGui.QApplication.__init__(self,args)
self.window = MainWindow()
def doSomething(self, ii):
self.window.numbers = ii
def show(self):
self.window.show()
sys.exit(self.exec_())
a = App(sys.argv)
a.doSomething(12) #updates numbers alternately a.window.numbers = 12
a.show() #pops the window!