не могу разобраться в чем ошибка. Pyqt5
нужно было сделать обычный калькулятор на Python с использованием PyQt5. Выдает ошибку, помогите пожалуйста. вот код:
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton
class Calculator(QWidget):
def __init__(self):
super().__init__(parent=None)
self.init_ui()
def init_ui(self):
grid = Q6ridLayout()
self.setlayout(grid)
btn_names = ['Cls', 'Bck', '', 'Close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+' ]
positions = [(i, j) for i in range(5) for j in range(4)]
for name, pos in zip(btn_names, positions);
if name == "":
continue
button = QPushButton(name)
grid.addWidget(button, *pos)
self.move(300, 150)
self.setWindowTitle("Calculator")
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
cals = Calculator()
sys.exit(app.exec_())
PyQt5.
Ответы (1 шт):
Автор решения: sLoNcE
→ Ссылка
Я так понял вы об этой ошибке - line 22 for name, pos in zip(btn_names, positions); ^ SyntaxError: invalid syntax
Вы использовали точку с запятой ; вместо двоеточия : в 22 строке кода. Также в вашем коде есть еще одна ошибка. В строке 10 вы написали Q6ridLayout() вместо QGridLayout()
Вот полный код с исправлениями:
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QGridLayout
class Calculator(QWidget):
def __init__(self):
super().__init__(parent=None)
self.init_ui()
def init_ui(self):
grid = QGridLayout()
self.setLayout(grid)
btn_names = ['Cls', 'Bck', '', 'Close',
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+']
positions = [(i, j) for i in range(5) for j in range(4)]
for name, pos in zip(btn_names, positions):
if name == "":
continue
button = QPushButton(name)
grid.addWidget(button, *pos)
self.move(300, 150)
self.setWindowTitle("Calculator")
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
cals = Calculator()
sys.exit(app.exec_())