Python 在UI中显示结果

Python 在UI中显示结果,python,qt,pyqt,pyside,Python,Qt,Pyqt,Pyside,我正在用pyside和Qt构建一个用户界面。我已经做了很好的计算,我想在UI中显示结果。 每个结果为1个浮点数,并存储在: self.dist_total_disp self.time_total_disp 我尝试过用如下标签显示它们: self.layout = QtGui.QVBoxLayout() self.plot_window =QtGui.QVBoxLayout() self.dist_time_label = QtGui.QLabel() sel

我正在用pyside和Qt构建一个用户界面。我已经做了很好的计算,我想在UI中显示结果。 每个结果为1个浮点数,并存储在:

self.dist_total_disp
self.time_total_disp
我尝试过用如下标签显示它们:

    self.layout = QtGui.QVBoxLayout()
    self.plot_window =QtGui.QVBoxLayout()

    self.dist_time_label = QtGui.QLabel()
    self.dist_time_label.setText("total distance = self.dist_total_disp \ntotal survey time = self.time_total_disp ")
    self.plot_window.addWidget(self.dist_time_label)

   ----COMPILE UI----

    self.setLayout(self.layout)
    self.layout.addLayout(self.plot_window)
但这里的问题是setText需要一个字符串,不能从字符串中调用self.dist_total_disp和self.time_total_disp

此外,我希望在VBox的右下方显示结果,但我不想将QVBoxLayout()更改为QHBoxLayout()

我觉得应该有一个更适合这个的QtGui工具,但我在文档中找不到

编辑: 请注意,计算是通过用户界面的输入完成的,这应该可以:

self.dist_time_label.setText("total distance = {0} \ntotal survey time = {1} ".format(self.dist_total_disp, self.time_total_disp))

要在
VBox的下方添加标签,应在其上方添加一个间隔符。

您需要使用要显示的值格式化字符串

self.dist_time_label.setText("total distance = %f\ntotal survey time = %f" % (self.dist_total_disp, self.time_total_disp))
要在右下侧显示标签,可以使用

self.plot_window.addWidget(self.dist_time_label, alignment=QtCore.Qt.AlignRight|QtCore.Qt.AlignBottom)