用python写的,pyqt5呈现
from PyQt5.QtWidgets import QApplication,QLineEdit,QWidget,QVBoxLayout,QLabel,QPushButton
import sys
from PyQt5 import QtGui,QtCore
from PyQt5.QtCore import QRect
class Window(QWidget):
def __init__(self):
super().__init__()
self.title = "闰年计算器"
self.left = 500
self.top = 200
self.width = 500
self.height = 400
self.InitWindow()
def InitWindow(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
hbox = QVBoxLayout()
self.label1 = QLabel(self)
self.label1.setFont(QtGui.QFont("Sanserif",18))
self.label1.setText("输入年份(如:1900)")
hbox.addWidget(self.label1)
self.lineEdit = QLineEdit(self)
self.lineEdit.setFont(QtGui.QFont("Sanserif",18))
hbox.addWidget(self.lineEdit)
self.button = QPushButton("计算")
self.button.clicked.connect(self.OnPressed)
hbox.addWidget(self.button)
self.label = QLabel(self)
self.label.setFont(QtGui.QFont("Sanserif",18))
hbox.addWidget(self.label)
self.setLayout(hbox)
self.show()
def OnPressed(self):
y = self.lineEdit.text()
y = int(y)
if y%4==0 and y%100 != 0 or y%400==0:
T = "{0}年是闰年".format(y)
else:
T = "{0}年不是闰年".format(y)
self.label.setText(T)
if __name__ == '__main__':
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())