簡體   English   中英

創建python對象錯誤的實例-如何調用super方法?

[英]Creating an instance of a python object error - how to call the super method?

如果我在一個文件(稱為gui.py)中定義了這樣的類,(其中QtWidgets是導入的模塊(PyQt5))

class Window(QtWidgets.QMainWindow):

    def __init__(self):
        super(Window, self).__init__(self)

        # other regular stuff in init...  

如何在另一個文件中創建此對象的實例? 即當我執行以下操作時,

import gui
window = gui.Window()

我收到錯誤“從未調用過Window類型的super-class__init __()”。 當我嘗試

window = gui.Window.super().__init__()

我得到錯誤類型對象“窗口”沒有屬性“超級”。

這應該工作:

class Window(QtWidgets.QMainWindow):

    def __init__(self):
        super().__init__()

(摘自https://pythonspot.com/category/pyqt5/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM