chore: using PySide6
This commit is contained in:
parent
422da04a3b
commit
6e0e68e151
@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
from PyQt6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
QMainWindow,
|
QMainWindow,
|
||||||
QWidget,
|
QWidget,
|
||||||
@ -7,8 +7,8 @@ from PyQt6.QtWidgets import (
|
|||||||
QPushButton,
|
QPushButton,
|
||||||
QLineEdit,
|
QLineEdit,
|
||||||
)
|
)
|
||||||
from PyQt6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
from PyQt6.QtGui import QKeyEvent
|
from PySide6.QtGui import QKeyEvent
|
||||||
|
|
||||||
|
|
||||||
class Calculator(QMainWindow):
|
class Calculator(QMainWindow):
|
||||||
@ -79,7 +79,7 @@ class Calculator(QMainWindow):
|
|||||||
# 创建显示结果的文本框
|
# 创建显示结果的文本框
|
||||||
self.display = QLineEdit()
|
self.display = QLineEdit()
|
||||||
self.display.setReadOnly(True)
|
self.display.setReadOnly(True)
|
||||||
self.display.setAlignment(Qt.AlignmentFlag.AlignRight)
|
self.display.setAlignment(Qt.AlignRight)
|
||||||
self.display.setMaxLength(15)
|
self.display.setMaxLength(15)
|
||||||
self.display.setMinimumHeight(80)
|
self.display.setMinimumHeight(80)
|
||||||
self.display.setText("0")
|
self.display.setText("0")
|
||||||
@ -120,26 +120,26 @@ class Calculator(QMainWindow):
|
|||||||
|
|
||||||
# 添加按键映射字典
|
# 添加按键映射字典
|
||||||
self.key_mapping = {
|
self.key_mapping = {
|
||||||
Qt.Key.Key_0: "0",
|
Qt.Key_0: "0",
|
||||||
Qt.Key.Key_1: "1",
|
Qt.Key_1: "1",
|
||||||
Qt.Key.Key_2: "2",
|
Qt.Key_2: "2",
|
||||||
Qt.Key.Key_3: "3",
|
Qt.Key_3: "3",
|
||||||
Qt.Key.Key_4: "4",
|
Qt.Key_4: "4",
|
||||||
Qt.Key.Key_5: "5",
|
Qt.Key_5: "5",
|
||||||
Qt.Key.Key_6: "6",
|
Qt.Key_6: "6",
|
||||||
Qt.Key.Key_7: "7",
|
Qt.Key_7: "7",
|
||||||
Qt.Key.Key_8: "8",
|
Qt.Key_8: "8",
|
||||||
Qt.Key.Key_9: "9",
|
Qt.Key_9: "9",
|
||||||
Qt.Key.Key_Plus: "+",
|
Qt.Key_Plus: "+",
|
||||||
Qt.Key.Key_Minus: "-",
|
Qt.Key_Minus: "-",
|
||||||
Qt.Key.Key_Asterisk: "*",
|
Qt.Key_Asterisk: "*",
|
||||||
Qt.Key.Key_Slash: "/",
|
Qt.Key_Slash: "/",
|
||||||
Qt.Key.Key_Period: ".",
|
Qt.Key_Period: ".",
|
||||||
Qt.Key.Key_Return: "=",
|
Qt.Key_Return: "=",
|
||||||
Qt.Key.Key_Enter: "=",
|
Qt.Key_Enter: "=",
|
||||||
Qt.Key.Key_Equal: "=",
|
Qt.Key_Equal: "=",
|
||||||
Qt.Key.Key_Escape: "C",
|
Qt.Key_Escape: "C",
|
||||||
Qt.Key.Key_Percent: "%",
|
Qt.Key_Percent: "%",
|
||||||
}
|
}
|
||||||
|
|
||||||
def keyPressEvent(self, event: QKeyEvent) -> None:
|
def keyPressEvent(self, event: QKeyEvent) -> None:
|
||||||
@ -147,18 +147,18 @@ class Calculator(QMainWindow):
|
|||||||
key = event.key()
|
key = event.key()
|
||||||
|
|
||||||
# 处理数字键盘的输入
|
# 处理数字键盘的输入
|
||||||
if event.modifiers() == Qt.KeyboardModifier.KeypadModifier:
|
if event.modifiers() == Qt.KeypadModifier:
|
||||||
if key == Qt.Key.Key_Plus:
|
if key == Qt.Key_Plus:
|
||||||
self.process_input("+")
|
self.process_input("+")
|
||||||
elif key == Qt.Key.Key_Minus:
|
elif key == Qt.Key_Minus:
|
||||||
self.process_input("-")
|
self.process_input("-")
|
||||||
elif key == Qt.Key.Key_Asterisk:
|
elif key == Qt.Key_Asterisk:
|
||||||
self.process_input("*")
|
self.process_input("*")
|
||||||
elif key == Qt.Key.Key_Slash:
|
elif key == Qt.Key_Slash:
|
||||||
self.process_input("/")
|
self.process_input("/")
|
||||||
elif key == Qt.Key.Key_Enter:
|
elif key == Qt.Key_Enter:
|
||||||
self.process_input("=")
|
self.process_input("=")
|
||||||
elif key == Qt.Key.Key_Period:
|
elif key == Qt.Key_Period:
|
||||||
self.process_input(".")
|
self.process_input(".")
|
||||||
|
|
||||||
# 处理普通键盘的输入
|
# 处理普通键盘的输入
|
||||||
@ -166,7 +166,7 @@ class Calculator(QMainWindow):
|
|||||||
self.process_input(self.key_mapping[key])
|
self.process_input(self.key_mapping[key])
|
||||||
|
|
||||||
# 处理退格键
|
# 处理退格键
|
||||||
elif key == Qt.Key.Key_Backspace:
|
elif key == Qt.Key_Backspace:
|
||||||
current_text = self.display.text()
|
current_text = self.display.text()
|
||||||
self.display.setText(current_text[:-1])
|
self.display.setText(current_text[:-1])
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
PyQt6>=6.0.0
|
PySide6>=6.0.0
|
||||||
pyinstaller>=6.0.0
|
PyInstaller>=6.0.0
|
Loading…
x
Reference in New Issue
Block a user