窗口小部件未在pyqt5中显示标签

时间:2019-07-24 09:32:45

标签: python pyqt pyqt5

我想在pyqt5应用程序中显示一个带有简单消息的窗口。为此,我创建了一个简单的小部件,布局和标签。我将标签添加到布局中,然后将布局分配给小部件,如下所示:

app = QApplication(sys.argv)
# Create a widget to store information
load_widget = QWidget()
# Create a label with the message to display
load_label = QLabel()
# Set label text
load_label.setText('Data being imported, please wait...')
# Create a layout for the widget
load_layout = QVBoxLayout()
# Add label to the layout
load_layout.addWidget(load_label)
# Set layout for the widget
load_widget.setLayout(load_layout)
# Set window title
load_widget.setWindowTitle('Read SD')
# Show the widget
load_widget.show()
sys.exit(app.exec_())

但是,窗口与标题一起显示,但是没有标签显示,如下图所示。

enter image description here

1 个答案:

答案 0 :(得分:0)

@eyllanesc指出这不是MRE,因为如果复制/粘贴并运行它,则会得到:

DF <-
structure(list(Value = c(2L, 0L, 5L, 4L, 4L, 7L, 9L), Length = c(0L, 
1L, 1L, 5L, 5L, 6L, 8L)), class = "data.frame", row.names = c("Subject1", 
"Subject2", "Subject3", "Subject4", "Subject5", "Subject6", "Subject7"
))

我已经扩展了您的代码并对其进行了正确格式化,并且效果很好

QWidget: Must construct a QApplication before a QWidget