ui.close后怎么打开
时间: 2024-02-03 16:04:34 浏览: 27
如果您是指在 Python 中使用 PyQt 或 PySide 开发 GUI 应用程序时,通过 `ui.close()` 关闭窗口后如何重新打开窗口,可以使用以下方式:
1. 在窗口的 `closeEvent` 中重新创建窗口对象,并将其显示出来:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
# 初始化界面等代码...
def closeEvent(self, event):
# 隐藏当前窗口
self.hide()
# 创建新的窗口对象
new_window = MyMainWindow()
new_window.show()
event.accept()
if __name__ == '__main__':
app = QApplication([])
main_window = MyMainWindow()
main_window.show()
app.exec_()
```
2. 将窗口对象存储在一个变量中,并在需要重新打开窗口时,将其重新显示出来:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
# 初始化界面等代码...
if __name__ == '__main__':
app = QApplication([])
main_window = MyMainWindow()
main_window.show()
# 关闭窗口
main_window.close()
# 重新显示窗口
main_window.show()
app.exec_()
```
这些方法都可以实现重新打开窗口的功能,您可以根据自己的需求选择其中的一种方式。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)