File tree Expand file tree Collapse file tree 3 files changed +43
-4
lines changed
Expand file tree Collapse file tree 3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 11# Filename: signals_slots.py
22
3- """Signals and Slots example."""
3+ """Signals and slots example."""
44
55import sys
66
1313
1414def greeting ():
1515 """Slot function."""
16- msg .setText ("Hello World!" )
16+ if msg .text ():
17+ msg .setText ("" )
18+ else :
19+ msg .setText ("Hello World!" )
1720
1821
1922app = QApplication (sys .argv )
Original file line number Diff line number Diff line change 1+ # Filename: signals_slots_partial.py
2+
3+ """Signals and slots example."""
4+
5+ import sys
6+ import functools
7+
8+ from PyQt5 .QtWidgets import QApplication
9+ from PyQt5 .QtWidgets import QWidget
10+ from PyQt5 .QtWidgets import QPushButton
11+ from PyQt5 .QtWidgets import QLabel
12+ from PyQt5 .QtWidgets import QVBoxLayout
13+
14+
15+ def greeting (who ):
16+ """Slot function."""
17+ if msg .text ():
18+ msg .setText ("" )
19+ else :
20+ msg .setText (f"Hello { who } " )
21+
22+
23+ app = QApplication (sys .argv )
24+ window = QWidget ()
25+ window .setWindowTitle ("Signals, and Slots" )
26+ layout = QVBoxLayout ()
27+
28+ btn = QPushButton ("Greet" )
29+ btn .clicked .connect (functools .partial (greeting , "World!" ))
30+
31+ layout .addWidget (btn )
32+ msg = QLabel ("" )
33+ layout .addWidget (msg )
34+ window .setLayout (layout )
35+ window .show ()
36+ sys .exit (app .exec_ ())
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def __init__(self):
4141 # Set some main window's properties
4242 self .setWindowTitle ("PyCalc" )
4343 self .setFixedSize (235 , 235 )
44- # Create and set the central widget and the general layout
44+ # Set the central widget and the general layout
4545 self .generalLayout = QVBoxLayout ()
4646 self ._centralWidget = QWidget (self )
4747 self .setCentralWidget (self ._centralWidget )
@@ -164,7 +164,7 @@ def main():
164164 # Show the calculator's GUI
165165 view = PyCalcUi ()
166166 view .show ()
167- # Create an instance of the model and the controller
167+ # Create instances of the model and the controller
168168 model = evaluateExpression
169169 PyCalcCtrl (model = model , view = view )
170170 # Execute calculator's main loop
You can’t perform that action at this time.
0 commit comments