久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='PZhvS'></tfoot>

<small id='PZhvS'></small><noframes id='PZhvS'>

    <legend id='PZhvS'><style id='PZhvS'><dir id='PZhvS'><q id='PZhvS'></q></dir></style></legend>
      • <bdo id='PZhvS'></bdo><ul id='PZhvS'></ul>

    1. <i id='PZhvS'><tr id='PZhvS'><dt id='PZhvS'><q id='PZhvS'><span id='PZhvS'><b id='PZhvS'><form id='PZhvS'><ins id='PZhvS'></ins><ul id='PZhvS'></ul><sub id='PZhvS'></sub></form><legend id='PZhvS'></legend><bdo id='PZhvS'><pre id='PZhvS'><center id='PZhvS'></center></pre></bdo></b><th id='PZhvS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PZhvS'><tfoot id='PZhvS'></tfoot><dl id='PZhvS'><fieldset id='PZhvS'></fieldset></dl></div>

    2. 運行后立即關(guān)閉窗口

      Window closes immediatelly after run(運行后立即關(guān)閉窗口)
        <tbody id='fNhT4'></tbody>
        <tfoot id='fNhT4'></tfoot>
        1. <legend id='fNhT4'><style id='fNhT4'><dir id='fNhT4'><q id='fNhT4'></q></dir></style></legend>
                <bdo id='fNhT4'></bdo><ul id='fNhT4'></ul>

                <small id='fNhT4'></small><noframes id='fNhT4'>

                <i id='fNhT4'><tr id='fNhT4'><dt id='fNhT4'><q id='fNhT4'><span id='fNhT4'><b id='fNhT4'><form id='fNhT4'><ins id='fNhT4'></ins><ul id='fNhT4'></ul><sub id='fNhT4'></sub></form><legend id='fNhT4'></legend><bdo id='fNhT4'><pre id='fNhT4'><center id='fNhT4'></center></pre></bdo></b><th id='fNhT4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fNhT4'><tfoot id='fNhT4'></tfoot><dl id='fNhT4'><fieldset id='fNhT4'></fieldset></dl></div>
              • 本文介紹了運行后立即關(guān)閉窗口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我的代碼用一個按鈕調(diào)用一個窗口.單擊按鈕時,調(diào)用另一個窗口.但是第二個窗口立即關(guān)閉

                My code calls one window with a button. When the button is clicked, call another window. But the second window closes immediately

                基本"和windows_two"是 pyuic5 從 .ui 文件中生成的 .py 庫

                "basic" and "windows_two" are .py libraries genereted by pyuic5 from .ui files

                import basic, windows_two
                from PyQt5 import QtCore, QtGui, QtWidgets
                
                if __name__ == "__main__":
                    
                    #Declarations
                    import sys
                    app = QtWidgets.QApplication(sys.argv)
                    
                    def Call_Second_Window():
                        #Second Screen
                        Form = QtWidgets.QWidget()
                        ui = windows_two.Ui_Form()
                        ui.setupUi(Form)
                        Form.show()
                        
                    def Call_Main_Window():
                        #MainWindow
                        MainWindow = QtWidgets.QMainWindow()
                        ui = basic.Ui_MainWindow()
                        ui.setupUi(MainWindow)      
                        ui.printButton.clicked.connect(Call_Second_Window) #click event to second window
                        MainWindow.show()
                        sys.exit(app.exec_())
                        
                    
                    Call_Main_Window()
                    
                

                怎么了?

                謝謝

                推薦答案

                只要變量是本地,它就會被收集垃圾".一旦函數(shù)返回;這意味著變量可能引用的所有內(nèi)容也將(可能)被刪除.

                Whenever a variable is local it gets "garbage collected" as soon as the function returns; this means that everything the variable might reference to will also be (possibly) deleted too.

                在您的情況下發(fā)生的情況是,在正確創(chuàng)建窗口時,當(dāng) Call_Second_Window 返回時(就在 Form.show 之后),它將立即被刪除(由于垃圾收集)()).

                What is happening in your case is that while the windows is correctly created, it will be immediately deleted (due to the garbage collection) when the Call_Second_Window returns (just after Form.show()).

                為了避免只有一個解決方案:使對對象的引用持久化.有多種方法可以實現(xiàn)這一目標(biāo),具體取決于具體情況.

                To avoid that there is only one solution: make the reference to the object persistent. There are various approaches to achieve that, depending on the situation.

                不幸的是,您的代碼有點不正統(tǒng)(尤其是從 PyQt 的角度來看),所以我正在重構(gòu)".它是為了使它更標(biāo)準(zhǔn)化、更好地面向?qū)ο螅腋匾氖牵子陂喿x.

                Unfortunately your code is a bit unorthodox (especially from a PyQt perspective), so I'm "refactoring" it in order to make it more standardized, better object oriented and, also importantly, easily readable.

                import basic, windows_two
                from PyQt5 import QtWidgets
                
                class MainWindow(QtWidgets.QMainWindow):
                    def __init__(self):
                        super().__init__()
                        self.ui = basic.Ui_MainWindow()
                        self.ui.setupUi(self)
                        self.ui.printButton.clicked.connect(self.call_Second_Window) 
                
                        self.secondWindow = None
                
                    def call_Second_Window(self):
                        if not self.secondWindow:
                            self.secondWindow = SecondWindow()
                        self.secondWindow.show()
                
                
                class SecondWindow(QtWidgets.QWidget):
                    def __init__(self):
                        super().__init__()
                        self.ui = windows_two.Ui_Form()
                        self.ui.setupUi(self)
                
                
                if __name__ == "__main__":
                    import sys
                    app = QtWidgets.QApplication(sys.argv)
                    
                    mainWindow = MainWindow()
                    mainWindow.show()
                
                    sys.exit(app.exec_())
                

                注意:如您所見,我將 call_Second_Window 的名稱更改為小寫的c",這是因為大寫名稱只能用于類和常量,而函數(shù)名稱應(yīng)始終以小寫字母開頭.這又是為了可讀性,這在編程中非常重要,也是 python 的核心原則之一.在官方 Python 代碼樣式指南.

                Note: As you can see, I changed the name of call_Second_Window with a lower "c", and that's because capitalized names should only be used for classes and constants, while function names should always start with a lower case. This is again for readability, which is very important in programming and one of the core principles of python. Read more about this and other important topics on the official Style Guide for Python Code.

                這篇關(guān)于運行后立即關(guān)閉窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 100%)
                How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進(jìn)度條?)

                <small id='RXj4r'></small><noframes id='RXj4r'>

              • <legend id='RXj4r'><style id='RXj4r'><dir id='RXj4r'><q id='RXj4r'></q></dir></style></legend>
                  <bdo id='RXj4r'></bdo><ul id='RXj4r'></ul>
                    <tfoot id='RXj4r'></tfoot>

                        1. <i id='RXj4r'><tr id='RXj4r'><dt id='RXj4r'><q id='RXj4r'><span id='RXj4r'><b id='RXj4r'><form id='RXj4r'><ins id='RXj4r'></ins><ul id='RXj4r'></ul><sub id='RXj4r'></sub></form><legend id='RXj4r'></legend><bdo id='RXj4r'><pre id='RXj4r'><center id='RXj4r'></center></pre></bdo></b><th id='RXj4r'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RXj4r'><tfoot id='RXj4r'></tfoot><dl id='RXj4r'><fieldset id='RXj4r'></fieldset></dl></div>
                            <tbody id='RXj4r'></tbody>
                          主站蜘蛛池模板: 天天色网站 | 成人av在线网站 | 91黄视频| 成人精品在线 | 国产乱码一区二区 | 中文字幕国产视频 | 免费黄色一级 | 国产免费无遮挡 | 精品免费国产 | 黄色三级大片 | 精品免费国产一区二区三区四区 | 特黄av | av黄页| 国产欧美自拍 | 精品一区二区在线播放 | 欧美黄色片在线观看 | 黄色大片在线 | 日韩在线视频一区 | 成人永久免费 | av福利在线 | 欧美午夜精品久久久久免费视 | 精品国产一区二区在线观看 | 爱搞逼综合网 | 成人在线视频免费观看 | 黄色国产网站 | 国产精品国产三级国产专区52 | 青青草免费在线 | 黄色aaa| 国产精品日韩精品 | 天天天干 | 亚洲精品一区中文字幕乱码 | 中文字幕亚洲欧美 | 精品在线观看视频 | 黑人精品一区二区 | 一区二区视频在线播放 | 日韩精品在线免费观看 | 国语对白做受欧美 | 黄色一级免费看 | 国产一区免费在线观看 | 色妞色视频一区二区三区四区 | 国产一级在线视频 |