pyqt5 运行其他文件函数修改控件信息代码例子
时间: 2023-03-27 11:02:38 浏览: 201
以下是一个 pyqt5 运行其他文件函数修改控件信息的代码例子:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel
import sys
import other_file
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(100, 100, 300, 200)
self.setWindowTitle('Example')
self.label = QLabel('Hello World!', self)
self.label.move(100, 50)
self.button = QPushButton('Change Text', self)
self.button.move(100, 100)
self.button.clicked.connect(self.change_text)
def change_text(self):
new_text = other_file.get_new_text()
self.label.setText(new_text)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
在这个例子中,我们创建了一个 `MainWindow` 类,它包含一个标签和一个按钮。当按钮被点击时,它会调用 `change_text` 函数,该函数会调用 `other_file` 中的 `get_new_text` 函数来获取新的文本,并将其设置为标签的文本。
阅读全文
相关推荐
















