Python/pyqt5/CODE/qt04x範例程式/qt0407_QLabel.py
2024-06-27 15:41:10 +08:00

49 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
'''
【簡介】
PyQT5中Qlabel範例
按住 Alt + N , Alt + P , Alt + O , Alt + C 切換元件控制項
'''
from PyQt5.QtWidgets import *
import sys
class QlabelDemo(QDialog):
def __init__(self ):
super().__init__()
self.setWindowTitle('Qlabel 範例')
nameLb1 = QLabel('&Name', self)
nameEd1 = QLineEdit( self )
nameLb1.setBuddy(nameEd1)
nameLb2 = QLabel('&Password', self)
nameEd2 = QLineEdit( self )
nameLb2.setBuddy(nameEd2)
btnOk = QPushButton('&OK')
btnCancel = QPushButton('&Cancel')
mainLayout = QGridLayout(self)
mainLayout.addWidget(nameLb1,0,0)
mainLayout.addWidget(nameEd1,0,1,1,2)
mainLayout.addWidget(nameLb2,1,0)
mainLayout.addWidget(nameEd2,1,1,1,2)
mainLayout.addWidget(btnOk,2,1)
mainLayout.addWidget(btnCancel,2,2)
def link_hovered():
print("當滑鼠滑過label-2標籤時觸發事件。")
def link_clicked():
print("當滑鼠點擊label-4標籤時觸發事件。" )
if __name__ == "__main__":
app = QApplication(sys.argv)
labelDemo = QlabelDemo()
labelDemo.show()
sys.exit(app.exec_())