如何在PyQt5中自动创建一个新窗口?

时间:2018-03-24 04:33:17

标签: python pyqt pyqt5

当我使用一个按钮来调用它时,创建一个新窗口的函数是有效的,当某些条件满足某些条件时它不起作用,这很奇怪。

from PyQt5 import QtWidgets, QtCore
from interface import Ui_Form as uiInterface
from chooseLauncherFile import Ui_Form as uiChooseLauncherFile

class MyInterface(uiInterface):
    def __init__(self):
        self.window = QtWidgets.QWidget()
        self.setupUi(self.window)

        self.threads = QtCore.QThread()
        self.threads.run = self.init
        self.threads.start()

        self.window.show()

    def init(self):
        self.util = Util(self)
        self.util.detectLauncher()
        self.syncToServer()  #this function should run after main window show

    def chooseLauncherFile(self):
        self.chooseLauncherWindow = QtWidgets.QWidget()
        self.chooseLauncherUi=MyChooseLauncherFile()
        self.chooseLauncherUi.setupUi(self.chooseLauncherWindow)
        self.chooseLauncherWindow.show()

class MyChooseLauncherFile(uiChooseLauncherFile):
    def confirm(self, item):
        EXEC_FILE = item.text()

class Util():
    def __init__(self, interface):
        self.interface = interface

    def detectLauncher(self):
        if True: #has been simplified here
            self.interface.chooseLauncherFile()

这些代码会使新的子窗口无响应,但是当我更改代码时就可以了,

def init(self):
        self.syncToServer()  #this function should run after main window show

self.pushButton.pressed.connect(self.chooseLauncherFile)
#this line come from another file 
#to use a button to call function

非常感谢您能帮助我制作顶级作品代码,在另一个世界中,自动创建一个新窗口而不使用按钮。

0 个答案:

没有答案
相关问题