from PyQt5.QtWidgets import *
import sys
class Qlabelbuddy(QDialog):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Qlabel与伙伴控件')
#创建热键
namelabel = QLabel('&Name:',self)
nameEdit = QLineEdit(self)
#设置伙伴控件
namelabel.setBuddy(nameEdit)
passlabel= QLabel('&Password:',self)
passLineEdit = QLineEdit(self)
passlabel.setBuddy(passLineEdit)
btn = QPushButton('&OK')
btnCancel = QPushButton('&Cancel')
#设置栅格布局
mainlayout = QGridLayout(self)
mainlayout.addWidget(namelabel,0,0)
mainlayout.addWidget(nameEdit,0,1,1,2)
mainlayout.addWidget(passlabel,1,0)
mainlayout.addWidget(passLineEdit,1,1,1,2)
mainlayout.addWidget(btn,2,1)
mainlayout.addWidget(btnCancel,2,2)
if __name__ == '__main__':
app= QApplication(sys.argv)
main= Qlabelbuddy()
main.show()
app.exit(app.exec_())
PyQt5 QLabel 与伙伴控件
最新推荐文章于 2022-07-27 22:24:45 发布