iT邦幫忙

0

VS Code PyQt5 無法顯示視窗問題

  • 分享至 

  • xImage

以下為可以正常顯示視窗的程式碼
import sys
from PyQt5 import QtWidgets
if name == 'main':
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.resize(400, 200)
w.setWindowTitle("hello PyQt5")
w.show()
exit(app.exec_())

以下程式碼為 ui 轉 py自動轉換的程式碼,執行時無跳出任何錯誤訊息,但不會顯示視窗,直接就關閉視窗了,想請問要如何解決,謝謝
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(130, 140, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(190, 220, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(100, 90, 47, 12))
self.label.setObjectName("label")

    self.retranslateUi(Dialog)
    QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
    _translate = QtCore.QCoreApplication.translate
    Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
    self.pushButton.setText(_translate("Dialog", "PushButton"))
    self.pushButton_2.setText(_translate("Dialog", "PushButton"))
    self.label.setText(_translate("Dialog", "TextLabel"))
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答