forked from muziing/PyQt_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-QObject类型判定-案例.py
42 lines (30 loc) · 920 Bytes
/
07-QObject类型判定-案例.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
from PyQt5.Qt import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QObject类型判定案例")
self.resize(500, 500)
self.move(400, 250)
self.setup_ui()
def setup_ui(self):
self.name()
def name(self):
label1 = QLabel(self)
label1.setText("这是label1")
label1.move(100, 100)
label2 = QLabel(self)
label2.setText("这是label2")
label2.move(200, 100)
btn = QPushButton(self)
btn.setText("点我")
btn.move(100, 200)
for widget in self.children():
if widget.inherits("QLabel"):
# print(widget, "是")
widget.setStyleSheet("background-color: cyan;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())