PyQt5 界面在启动后立即关闭

PyQt5 interface immediately closes after launch

我正在尝试为我的市场程序创建一个带有刷新按钮的界面。问题是 window 在打开后几乎立即关闭。我检查了一些解决方案,但我无能为力,因为我不确定问题是关于按钮还是关于 class 系统,因为我没有使用 classes.

的经验
import sys
import requests
from bs4 import BeautifulSoup
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtWidgets,QtGui,QtCore

class Pencere(QtWidgets.QWidget):

    def __init__(self):

        super().__init__()

        self.init_ui()
    
    
    def  init_ui(self):

        app = QtWidgets.QApplication(sys.argv)

        window = QtWidgets.QWidget()
        window.setWindowTitle("Markets")
        
        #window.setStyleSheet("background-color: white;")
        
        window.setGeometry(670,300,400,430)
        
        ####################################################    VERİLERİ ALMA
        
        self.url = "https://www.doviz.com//"

        self.response = requests.get(self.url)

        self.html_content = (self.response).content

        self.soup = BeautifulSoup((self.html_content),"html.parser")

        self.titles1 = self.soup.find("span",{"data-socket-key":"USD"})
        self.titles2 = self.soup.find("span",{"data-socket-key":"EUR"})
        self.titles3 = self.soup.find("span",{"data-socket-key":"bitcoin"})
        self.titles4 = self.soup.find("span",{"data-socket-key":"XU100"})    
        self.titles1 = self.titles1.text
        self.titles2 = self.titles2.text
        self.titles3 = self.titles3.text
        self.titles4 = self.titles4.text
        
        ####################################################    RESİMLERİ KOYMA
        
        self.image1 = QtWidgets.QLabel(window) 
        self.image1.setPixmap(QtGui.QPixmap("jdollar.png"))
        self.image1.move(50,50)
        
        self.image2 = QtWidgets.QLabel(window) 
        self.image2.setPixmap(QtGui.QPixmap("jeuro.png"))
        self.image2.move(50,120)
        
        self.image3 = QtWidgets.QLabel(window) 
        self.image3.setPixmap(QtGui.QPixmap("jbtc.png"))
        self.image3.move(50,190)
        
        self.image4 = QtWidgets.QLabel(window) 
        self.image4.setPixmap(QtGui.QPixmap("jbist.png"))
        self.image4.move(58,260)
        
        ####################################################    SAYILARI YAZDIRMA
        
        self.text1 = QtWidgets.QLabel(window)
        self.text1.setText(self.titles1)    
        self.text1.move(125,68)

        self.text2 = QtWidgets.QLabel(window)
        self.text2.setText(self.titles2)    
        self.text2.move(125,138)

        self.text3 = QtWidgets.QLabel(window)
        self.text3.setText(self.titles3)    
        self.text3.move(125,278)
        
        self.text4 = QtWidgets.QLabel(window)
        self.text4.setText(self.titles4)    
        self.text4.move(125,208)

        ####################################################    BUTONLARI OLUŞTURMA

        self.button1 = QtWidgets.QPushButton(window)
        self.button1.setText("Refresh")
        self.button1.move(150,330)
        self.button1.clicked.connect(self.__init__)
        
        self.button2 = QtWidgets.QPushButton(window)
        self.button2.setText("Exit")
        self.button2.move(150,360)
        
        ####################################################    EKRANI AÇMA
        
        self.show()
    
    def stats(self):
        
        self.url = "https://www.doviz.com//"

        self.response = requests.get(self.url)

        self.html_content = (self.response).content

        self.soup = BeautifulSoup((self.html_content),"html.parser")

        self.titles1 = self.soup.find("span",{"data-socket-key":"USD"})
        self.titles2 = self.soup.find("span",{"data-socket-key":"EUR"})
        self.titles3 = self.soup.find("span",{"data-socket-key":"bitcoin"})
        self.titles4 = self.soup.find("span",{"data-socket-key":"XU100"})    
        self.titles1 = self.titles1.text
        self.titles2 = self.titles2.text
        self.titles3 = self.titles3.text
        self.titles4 = self.titles4.text


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Pencere()
    window.show()
    app.exec_()

你应该删除 app = QtWidgets.QApplication(sys.argv) 参与

def  init_ui(self):

        app = QtWidgets.QApplication(sys.argv)

您正在使用两个 QApplications。虽然你只能使用一个。