简体   繁体   English

使用 pyqt5 gui 连接 tkinter 窗口

[英]Connect tkinter window with pyqt5 gui

How can I connect Tkinter window with pyqt5 Gui?如何将 Tkinter 窗口与 pyqt5 Gui 连接?

like pressing a push button in pyqt5 Gui and Tkinter window should pop up就像在 pyqt5 Gui 中按下一个按钮,应该弹出 Tkinter 窗口

I have two tkinter window which I want to popup separately after pressing different pushbuttons for each if I press any button, both windows popup together multiple times我有两个 tkinter 窗口,如果我按下任何按钮,我想在按下不同的按钮后分别弹出,两个窗口一起弹出多次

like pressing a push button in pyqt5 gui and tkinter window should pop up就像在 pyqt5 gui 中按下一个按钮,tkinter 窗口应该弹出

The solution is to have one class using Tkinter and the other using PyQt5.解决方案是让一个类使用 Tkinter,另一个类使用 PyQt5。

However, while this solution does work it leads to a reoccurring error, which does not affect the code itself.然而,虽然这个解决方案确实有效,但它会导致重复出现的错误,这不会影响代码本身。 You will need to call the class via the PyQT5 code.您将需要通过 PyQT5 代码调用该类。 Here is a solution below:下面是一个解决方案:

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_())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM