出乎意外想起以前一贯想写个大致的计算器,明日就写了风华正茂晃,分界面某个简陋,可是幼功效达成没不正常
以下是源码:
# --*-- coding:utf-8 --*--
import sys
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtGui import QFont
class Calculator(QtWidgets.QWidget):
def __init__(self):
super(Calculator, self).__init__()
self.initUI()
self.reset()
self.display.setText("0")
def initUI(self):
self.resize(600,650)
self.setWindowTitle('简易计算器')
Grid = QtWidgets.QGridLayout()
self.display = QtWidgets.QLineEdit('')
self.display.setFont(QFont("Times", 20))
self.display.setReadOnly(True)
self.display.setAlignment(QtCore.Qt.AlignRight)
self.display.setMaxLength(20)
Grid.addWidget(self.display, 0, 0, 1, 4)
names = ['C', '(', 'Del', '+',
'7', '8', '9', '-',
'4', '5', '6', '*',
'1', '2', '3', '/',
'0', '.', ')', '=']
pos = [(0, 0), (0, 1), (0, 2), (0, 3),
(1, 0), (1, 1), (1, 2), (1, 3),
(2, 0), (2, 1), (2, 2), (2, 3),
(3, 0), (3, 1), (3, 2), (3, 3),
(4, 0), (4, 1), (4, 2), (4, 3)]
c = 0
for name in names:
button = QtWidgets.QPushButton(name)
button.setFixedSize(QtCore.QSize(100, 60))
button.setFont(QFont('Times', 30))
button.clicked.connect(self.ButtonClicked)
Grid.addWidget(button, pos[c][0] + 1, pos[c][1])
c = c + 1
self.setLayout(Grid)
def ButtonClicked(self):
text = self.sender().text()
if text == "=":
r = eval(self.number)
result = str(r).decode('utf-8')
self.display.setText(str(result)) #计算结果
self.number = result
elif text == "Del":
self.number = self.number[:-1]
self.display.setText(self.number)
elif text == "C":
self.reset()
self.display.setText(self.number)
else:
if text in "+-*/":
self.number = self.number + text
else:
self.number = self.number + text if self.number != "0" else text
self.display.setText(self.number)
def reset(self):
self.number = "0"
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ex = Calculator()
ex.show()
sys.exit(app.exec_())
不想写啊,不想写!
多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费多写都浪费
不想思忖的时候就画画吧,不想写作的时候就画画吧,不想睡觉的时候就画画吧,不想出口的时候就画画吧,不想外出的时候就画画吧,不想上学的时候就画画吧,不想上班的时候就画画吧,不想上进的时候就画画吧,不想直面的时候就画画吧,堕落就贪腐地画画吧,最佳堕完结书法大师吧。
再怎么给自家鸡汤灌,再怎么给自个儿打鸡血,再怎么威逼利诱……小编后天就是不想写啊,不想写。
像呶呶不休说话雷同地描绘吧,像意识流写字同样地画画吧,像玩手提式有线电话机刷交际圈网页相符地描绘吧。
休假过后,第一天上班,心情能爽吗?不能够!还碰着检查了,能爽吗?不可能!冷到已经供暖,皮肤要干裂开,小编以至不掌握,还全力给保护皮肤品找事,能爽吗?不能够!居然有一点点小胸口痛,动人嗓门形成唐老鸭音,能爽吗?无法!学习摄影,才开掘自身连线条都画不直,能爽吗?不可能!……这么多无法,让小编写什么写?不写!坚决不写!
不过,不过,依然要24钟头写五篇千字文啊
本人决定了,今天不写!
写不出来写不出来写不出去写不出去写不出去写不出去写不出来写不出来写不出来
不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!不写!
写不出来写不出来写不出来写不出去写不出去写不出去写不出来写不出来写不出来