Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将Python 3 Tkinter模块作为小部件嵌入PyQT5中_Python 3.x_Tkinter_Pyqt5 - Fatal编程技术网

Python 3.x 将Python 3 Tkinter模块作为小部件嵌入PyQT5中

Python 3.x 将Python 3 Tkinter模块作为小部件嵌入PyQT5中,python-3.x,tkinter,pyqt5,Python 3.x,Tkinter,Pyqt5,第一篇文章是python的新手,因此,如果文章的格式很奇怪或者编码错误很愚蠢,请道歉 我使用tkinter创建了一个模块,希望将其嵌入pyQt5主窗口小部件中 这是tkinter模块,名为Del.py,我正在尝试导入 class Delfiles(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.mw = self.mainwindow() def mainwindow(self):

第一篇文章是python的新手,因此,如果文章的格式很奇怪或者编码错误很愚蠢,请道歉

我使用tkinter创建了一个模块,希望将其嵌入pyQt5主窗口小部件中

这是tkinter模块,名为Del.py,我正在尝试导入

class Delfiles(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.mw = self.mainwindow()

    def mainwindow(self):
        # mainwindow formatting

    def dellist(self):
        # delete function for buttons in mainwindow


class Results(tk.Toplevel):
    def __init__(self):
        tk.Toplevel.__init__(self)
    # toplevel popup that appears after dellist function runs

# root = Delfiles()
# root.mainloop()
这是pyqt5模块的一部分,我一直在尝试将tkinter模块嵌入其中

class SpreadSheet(QMainWindow):
    def __init__(self, rows, cols, parent=None):
        super(SpreadSheet, self).__init__(parent)
        self.rows = rows
        self.cols = cols
        self.cells = {}

        self.create_table1()
        self.create_table2()
        deletefiles = Del.mw()
        self.centralwidget = QWidget()

        self.vlayout = QVBoxLayout()
        self.hlayout = QHBoxLayout()
        self.vlayout.addWidget(self.table1)
        self.vlayout.addWidget(self.table2)
        self.hlayout.addLayout(self.vlayout)
        self.hlayout.addWidget(deletefiles)
        self.centralwidget.setLayout(self.hlayout)

        self.table1.cellDoubleClicked.connect(self.celldoubleclicked)
        self.table2.installEventFilter(self)

        self.setCentralWidget(self.centralwidget)
        self.show()

if __name__ == __main__:
    app = QApplication(sys.argv)
    sheet = SpreadSheet(5, 5)
    sheet.resize(1500, 900)
    sheet.show()
    sys.exit(app.exec_())

# https://negfeedback.blogspot.com/2017/12/a-simple-gui-spreadsheet-in-less-than.html
#link to source code for the pyqt5 module I'm working with
每次我尝试在嵌入tkinter模块的情况下运行pyqt模块时,tkinter模块要么在pyqt5模块的顶部打开,要么出现以下错误

Exception in Tkinter callback
AttributeError: module 'Del' has no attribute 'mw'

非常感谢您的帮助

您不能在tkinter中创建窗口并在PyQT5应用程序中使用它们。每个GUI工具包都有一个对另一个一无所知的呈现模型

不要合并两个服务相同的库,为什么要使用tkinter?tkinter有哪些功能没有PyQt5?。特别是,您无法组合2个GUI库,因为它们需要一个事件循环(分别是PyQt5和Tkinter的app.exec_uu2;()和root.mainloop())才能工作,但如果同时使用这两个库,它们将被阻止。Del.py模块是我编写的第一个代码,我只是随机使用Tkinter。我在网上找到了pyqt5模块,该模块帮助我解决了另一个问题,并试图修改该代码,使其也包含Del.py代码的功能。我只是想尝试导入Del方法,以避免在pyqt5中“重新发明轮子”,而不是因为我觉得必须使用tk。但是,如果最好在pyqt5中重新创建方法,以避免混合库,我想我只能这样做了。谢谢没错,这就是你要做的。