久久久久久久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. 運行后立即關閉窗口

      Window closes immediatelly after run(運行后立即關閉窗口)
        <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>
              • 本文介紹了運行后立即關閉窗口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我的代碼用一個按鈕調用一個窗口.單擊按鈕時,調用另一個窗口.但是第二個窗口立即關閉

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

                怎么了?

                謝謝

                推薦答案

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

                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)建窗口時,當 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)這一目標,具體取決于具體情況.

                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 的角度來看),所以我正在重構".它是為了使它更標準化、更好地面向對象,而且更重要的是,更易于閱讀.

                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",這是因為大寫名稱只能用于類和常量,而函數名稱應始終以小寫字母開頭.這又是為了可讀性,這在編程中非常重要,也是 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.

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

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

                相關文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 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 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

                <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>
                          主站蜘蛛池模板: 国产成人久久久 | 天堂va在线 | 日本a视频 | 欧美视频一区二区三区 | 久久精品日产第一区二区三区 | 精品一区欧美 | 国产成人在线一区二区 | 成人乱人乱一区二区三区软件 | 亚洲精品一区二区三区 | 一区二区三区免费 | 天天看天天爽 | 成年人在线观看视频 | 国产小u女发育末成年 | 欧美一级三级 | 久久se精品一区精品二区 | 国产精品久久久久久久久图文区 | 日本特黄a级高清免费大片 特黄色一级毛片 | 精品免费 | 久久精品国产精品青草 | 国产免费一区二区 | 国产www成人 | 欧美久 | 五月花丁香婷婷 | 国产精品3区 | 日韩成人免费在线视频 | 色综合99 | 久久免费精品视频 | 国产精品无 | 97视频在线观看网站 | 国产精品久久一区二区三区 | 一区二区三区四区在线播放 | 日韩有码在线观看 | 国产资源在线播放 | 国产精品久久久久久妇女6080 | 日韩电影中文字幕 | 国产一二三区电影 | 精产国产伦理一二三区 | 亚洲人成网站777色婷婷 | 日本一区二区三区四区 | 国产目拍亚洲精品99久久精品 | www.色.com|