問題描述
我真的希望有人可以幫助我解決這個問題.我正在嘗試開始使用 pyqt5
,并且幾乎從我正在學習的課程中復制了這段代碼.代碼似乎執行沒有任何問題,但我應該看到的窗口根本沒有出現,我做錯了什么?順便說一下,我正在研究 ubuntu 18
I really hope someone can help me out on this one.
Im trying to get started with using pyqt5
, and have pretty much copied this code from a course that i am taking. the code seems to execute without any problems, but the window that i should be seeing is simply not appearing, what am I doing wrong?
Im working on ubuntu 18
by the way
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Page(QWidget):
def __init__(self, parent=None):
super(Page, self).__init__(parent)
my_label = QLabel("This is my labet")
layout = QVBoxLayout()
layout.addWidget(my_label)
mainLayout = QGridLayout()
mainLayout.addLayout(layout, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("my first Qt app")
if __name__ == "__mongo__":
import sys
print("LOEREE")
app = QApplication(sys.argv)
window = Page()
window.show()
推薦答案
在你的例子中有一些拼寫錯誤,最后沒有一行 sys.exit (app.exec _ ())
它啟動了應用程序的主循環.從這里開始處理事件.
In your example there were some typos and at the end there was no line sys.exit (app.exec _ ())
which starts the main loop of the application. From here begins the processing of events.
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Page(QWidget):
def __init__(self, parent=None): # __init__
super(Page, self).__init__(parent) # __init__
my_label = QLabel("This is my labet")
layout = QVBoxLayout()
layout.addWidget(my_label)
mainLayout = QGridLayout()
mainLayout.addLayout(layout, 0, 1)
self.setLayout(mainLayout)
self.setWindowTitle("my first Qt app")
if __name__ == '__main__': #
import sys
print("LOEREE")
app = QApplication(sys.argv)
window = Page()
window.show()
sys.exit(app.exec_()) # !!!
這篇關于pyqt5不顯示窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!