self.label1.setText("坐标:" + str(info[0])+","+str(info[1])+","+str(info[2])+","+str(info[3]))把这个程序中点击按钮后显示的信息输出
时间: 2024-05-01 14:19:14 浏览: 175
这段程序会在按钮被点击后将信息显示在名为label1的标签上,输出信息为坐标信息,格式为(info[0], info[1], info[2], info[3]),其中info为一个包含4个元素的列表。代码如下:
```
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('MyWidget')
self.button = QPushButton('Click me!', self)
self.button.move(100, 100)
self.button.clicked.connect(self.showInfo)
self.label1 = QLabel('Coordinates:', self)
self.label1.move(100, 50)
self.show()
def showInfo(self):
info = [1, 2, 3, 4] # 假设这是获取到的坐标信息
self.label1.setText("Coordinates: " + str(info[0])+","+str(info[1])+","+str(info[2])+","+str(info[3]))
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyWidget()
sys.exit(app.exec_())
```
阅读全文