当前位置:网站首页>Pyqt5 learning pit encounter and pit drainage (2) buttons in qformlayout layout cannot be displayed
Pyqt5 learning pit encounter and pit drainage (2) buttons in qformlayout layout cannot be displayed
2022-07-29 04:29:00 【Lishizhen land】
At first, the source code is as follows :
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
#Qmessagebox
# class MessageBox(QMainWindow):
# def __init__(self, parent=None):
# super(MessageBox, self).__init__(parent)
# self.setWindowTitle("QDialog Demo")
# self.resize(350,300)
#
# self.btn = QPushButton(self)
# self.btn.setText(" Pop-up dialog box ")
# self.btn.clicked.connect(self.showmsg1)
#
# def showmsg1(self):
# message = QMessageBox.critical(self,"messagebox"," Confirmation window ",QMessageBox.Ok | QMessageBox.Cancel,QMessageBox.Ok)
#
#
# if __name__ == "__main__":
# app = QApplication(sys.argv)
# box = MessageBox()
# box.show()
# sys.exit(app.exec_())
class InputDialog(QMainWindow):
def __init__(self, parent=None):
super(InputDialog, self).__init__(parent)
self.setWindowTitle("InputDialog Demo")
layout = QFormLayout()
self.btn1 = QPushButton(" Get the options in the list ")
self.btn1.clicked.connect(self.getItem)
self.lb1 = QLineEdit()
layout.addRow(self.btn1,self.lb1)
self.btn2 = QPushButton(" Get string ")
self.btn2.clicked.connect(self.getText)
self.lb2 = QLineEdit()
layout.addRow(self.btn2,self.lb2)
self.btn3 = QPushButton(" Get an integer ")
self.btn3.clicked.connect(self.getInt)
self.lb3 = QLineEdit()
layout.addRow(self.btn3,self.lb3)
self.setLayout(layout)
def getItem(self):
items = {
"C","c++","JAVA",'Python'}
item , ok = QInputDialog.getItem(self,"select inputdialog"," list ",items,0,False)
if ok and item:
self.lb1.setText(item)
def getText(self):
text , ok = QInputDialog.getText(self,"Text inputdialog"," Enter a name ")
if ok:
self.lb2.setText(str(text))
def getInt(self):
num , ok = QInputDialog.getInt(self,"Int inputdialog"," Input integer ")
if ok:
self.lb2.setText(str(num))
if __name__ == "__main__":
app = QApplication(sys.argv)
box = InputDialog()
box.show()
sys.exit(app.exec_())
After searching online for a long time, I couldn't find a solution , And then it came to me , It seems that the inherited things in the class are not quite right , Then I tried to change it to QWidget, It works . Although I don't know why , But the problem was finally solved .
If someone knows why, I hope you can leave me a message .
边栏推荐
猜你喜欢

String, array, generalized table (detailed)

Common components of solder pad (2021.4.6)

MySQL - 深入解析MySQL索引数据结构

Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)

JVM (heap and stack) memory allocation

11. Backup switch

6. Pytest generates an allure Report

visio画网格

HC06 HC05 BT

用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
随机推荐
Update learning materials daily
oracle 更新和删除数据
Model tuning, training model trick
不会就坚持62天吧 单词之和
TypeError: Cannot read properties of undefined (reading ‘then‘)
It won't last for 70 days. The k-largest number in the array
Leftmost prefix principle of index
恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
Pytorch GPU and CPU models load each other
Jenkins 参数化构建中 各参数介绍与示例
Post export data, return
SQL time fuzzy query datediff() function
不会就坚持61天吧 最短的单词编码
Back propagation process of manual BP neural network
10.回退消息
11.备份交换机
Laya中的A星寻路
Labelme cannot open the picture
Realize the effect of univariate quadratic equation through JS. Enter the coefficients of a, B and C to calculate the values of X1 and x2
settings.xml