我如何连接Tkinter窗口和pyqt5 Gui?如在pyqt5 GUI中按下按钮,应弹出Tkinter窗口我有两个tkinter窗口,我想在按下不同的按钮后分别弹出,如果我按下任何按钮,两个窗口一起弹出多次如按下pyqt5 gui中的按钮,tkinter窗口应弹出
qjp7pelc1#
解决方案是让一个类使用Tkinter,另一个使用PyQt5。然而,虽然这个解决方案确实有效,但它会导致一个重复出现的错误,这并不影响代码本身。您需要通过PyQT5代码调用该类。下面是一个解决方案:
from PySide2.QtCore import * from PySide2.QtWidgets import * from PySide2.QtGui import * from tkinter import * from tkinter.ttk import Progressbar from tkinter.ttk import Combobox from tkinter.ttk import Notebook from tkinter.ttk import Treeview from PIL import Image, ImageTk import tkinter.font class Widget2(): def __init__(self, parent): self.gui(parent) def gui(self, parent): if parent == 0: self.w2 = Tk() self.w2.geometry('130x60') else: self.w2 = Frame(parent) self.w2.place(x = 0, y = 0, width = 130, height = 60) self.button1 = Button(self.w2, text = "Button", font = tkinter.font.Font(family = "Calibri", size = 9), cursor = "arrow", state = "normal") self.button1.place(x = 20, y = 20, width = 90, height = 22) class Widget1(QWidget): def __init__(self, parent=None): super(Widget1, self).__init__(parent) self.gui() def gui(self): self.w1 = self self.w1.setAutoFillBackground(True) self.w1.setWindowTitle("") self.w1.resize(500, 450) self.w1.setCursor(Qt.ArrowCursor) self.w1.setToolTip("") self.button1 = QToolButton(self.w1) self.button1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.button1.setText("Button") self.button1.move(9, 214) self.button1.resize(482, 22) self.button1.setCursor(Qt.ArrowCursor) self.button1.setToolTip("") self.button1.clicked.connect(self.event) return self.w1 def event(self): b = Widget2(0) b.w2.mainloop() if __name__ == '__main__': import sys app = QApplication(sys.argv) a = Widget1() a.show() sys.exit(app.exec_())
1条答案
按热度按时间qjp7pelc1#
解决方案是让一个类使用Tkinter,另一个使用PyQt5。
然而,虽然这个解决方案确实有效,但它会导致一个重复出现的错误,这并不影响代码本身。您需要通过PyQT5代码调用该类。下面是一个解决方案: