输入某一个出生年月就能知道某人生肖和星座

开发环境:Visual Studio Code

操作系统:Microsoft Window 10

Python版本:3.7

1、PyQt设计界面:

输入某一个出生年月就能知道某人生肖和星座_第1张图片

2、对象命名:
输入某一个出生年月就能知道某人生肖和星座_第2张图片

3、源程序:

# 系统包
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# 项目包
from Ui_MainWindow import Ui_MainWindow

class CMainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        super(CMainWindow, self).__init__(parent)
        self.setupUi(self)

        # 主窗体设置
        self.show()
    def Enter(self):

        nian = int(self.txtNumber1.text())   #在PYqt界面中设置好三个函数,分别为年、月、日,并且标注好,年为整数型函数,
        yue = self.txtNumber2.text()
        ri = self.txtNumber3.text()
        x = (nian-100)%12+1        #这里用一个计算年份的公式,所输入的年份,减去一百之后除以十二然后在加一,这样算出的数字为1-12中的某一个数,然后就是所得出的生肖。
        
        if x == 1:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属鼠"         
        if x == 2:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属牛" 
        if x == 3:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属虎"
        if x == 4:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属兔"
        if x == 5:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属龙"
        if x == 6:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属蛇"
        if x == 7:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属马"
        if x == 8:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属羊"
        if x == 9:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属猴"
        if x == 10:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属鸡"   
        if x == 11:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属狗"
        if x == 0:
            strOutnian =str(nian) + "." + str(yue) + "." + str(ri) + ",属猪"
        self.labResult.setText(strOutnian)
        a = int(yue + ri)
        print(a)         #输入某人的月跟日,因为这个用的是字符型函数,因此所输入的月、日会在设置的一个区里面,故产生结果
        if a < 218 and a > 120:
            strOutyueri = "我的星座是水瓶座"
        elif a < 320 and a > 219:
            strOutyueri = "我的星座是双鱼座"
        elif a < 419 and a > 321:
            strOutyueri = "我的星座是白羊座"
        elif a < 520 and a > 420:
            strOutyueri = "我的星座是金牛座"
        elif a < 621 and a > 521:
            strOutyueri = "我的星座是双子座"
        elif a < 722 and a > 622:
            strOutyueri = "我的星座是巨蟹座"
        elif a < 822 and a > 723:
            strOutyueri = "我的星座是狮子座"
        elif a < 922 and a > 823:
            strOutyueri = "我的星座是处女座"
        elif a < 1023 and a > 923:
            strOutyueri = "我的星座是天秤座"
        elif a < 1122 and a > 1024:
            strOutyueri = "我的星座是天蝎座"
        elif a < 1221 and a > 1123:
            strOutyueri = "我的星座是射手座"
        else :
            strOutyueri = "我的星座是摩羯座"
        self.labResult.setText(self.labResult.text() + ','+ strOutyueri)
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = CMainWindow()
    sys.exit(app.exec_())

你可能感兴趣的:(输入某一个出生年月就能知道某人生肖和星座)