所以....我正在使用 Python 的 PyQt 库来制作一个 Graphics 类,该类抽象出 QtGui 类的大部分功能。稍后我将在我的其他项目中使用它。这似乎工作正常,除了尽管创建了窗口,但按钮和其他小部件没有显示。import sysfrom PyQt4 import QtGuiclass Graphics: def __init__(self): self.app=QtGui.QApplication(sys.argv) self.widgets={} self.labels={} self.buttons={} def getApp(self): return self.app def newWidget(self,name:str): self.widgets[name]=QtGui.QWidget() return self.widgets[name] def addButton(self,name:str,text:str): self.buttons[name]=QtGui.QPushButton(text) return self.buttons[name] def addLabel(self,name:str,text:str): self.labels[name]=QtGui.QLabel() self.labels[name].setText(text) return self.labels[name] def start(self): for widget in self.widgets: self.widgets[widget].show() sys.exit(self.app.exec_())^ 那是代码。下面显示了我是如何实现这个类的from graphics import Graphicsgui=Graphics()w1=gui.newWidget("hmm")bt1=gui.addButton("hey","hello")print(bt1)gui.start()如果您能提供有关为什么会发生这种情况的见解,那就太好了。谢谢
添加回答
举报
0/150
提交
取消