久久久久久久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.

                在您的情況下發生的情況是,在正確創建窗口時,當 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()).

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

                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.

                不幸的是,您的代碼有點不正統(尤其是從 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模板網!

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

                相關文檔推薦

                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>
                          主站蜘蛛池模板: 国产精品美女久久久久久久久久久 | 亚洲一区二区三 | 一级片视频免费观看 | 精彩视频一区二区三区 | 亚洲网站在线观看 | 欧美日韩a | 国产精品成人一区二区三区 | 欧美精品在线一区二区三区 | 日本不卡一区二区三区 | 欧美精品一区免费 | 99久久婷婷 | 国产黄色av电影 | 超碰激情 | 国产精品久久国产精品 | 91在线免费观看网站 | 成人精品视频 | 特级丰满少妇一级aaaa爱毛片 | 亚洲精选一区二区 | 99久视频| 国产精品视频久久久久久 | 成年免费大片黄在线观看一级 | 日韩精品一区在线观看 | 亚洲精久久| 黄色网毛片 | 日韩激情视频一区 | 国产一区二区久久久 | 18av在线播放 | 亚洲一区久久 | 欧美一区二区三区的 | 久久一二区 | 蜜桃在线一区二区三区 | 97色在线视频 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 国产亚洲网站 | 亚洲一区二区精品视频 | 国产高清精品一区二区三区 | 国产精品无码永久免费888 | 成人性生交大片免费看中文带字幕 | 欧美日韩精品久久久免费观看 | 国产精品亚洲一区 | 欧美自拍日韩 |