Skip to content

Commit 583d357

Browse files
committed
TR update
1 parent 55e754a commit 583d357

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

pyqt-calculator-tutorial/examples/signals_slots.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Filename: signals_slots.py
22

3-
"""Signals and Slots example."""
3+
"""Signals and slots example."""
44

55
import sys
66

@@ -13,7 +13,10 @@
1313

1414
def 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

1922
app = QApplication(sys.argv)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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_())

pyqt-calculator-tutorial/pycalc/pycalc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)