页面文件基本🆗了
接下来主要是完成槽函数enter()
这个2.0版本主要实现了人生的逻辑,在人生出现转折的时候会跳出可选择的对话框

每个窗口一个线程太困难了,以后再学多线程吧

目前感觉这个enter()函数太长太累赘了,可能后续要把它拆分成多个函数/多个类
这样的话也便于实现特殊事件跳出对话框的机制
如果继续这么累赘下去的话,人物类型,时代就无法实现了
`
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(664, 593)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 10, 101, 51))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(280, 390, 121, 101))
self.pushButton.setObjectName("pushButton")
self.spinBox = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox.setGeometry(QtCore.QRect(160, 100, 81, 61))
self.spinBox.setObjectName("spinBox")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 100, 101, 61))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(320, 110, 111, 41))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(430, 120, 121, 41))
self.lineEdit.setObjectName("lineEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(40, 230, 101, 41))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(160, 240, 101, 31))
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(320, 240, 91, 31))
self.label_5.setObjectName("label_5")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(430, 240, 121, 31))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(40, 330, 51, 16))
self.label_6.setObjectName("label_6")
self.spinBox_2 = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox_2.setGeometry(QtCore.QRect(90, 330, 51, 31))
self.spinBox_2.setObjectName("spinBox_2")
self.label_7 = QtWidgets.QLabel(self.centralwidget)
self.label_7.setGeometry(QtCore.QRect(191, 330, 51, 20))
self.label_7.setObjectName("label_7")
self.spinBox_3 = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox_3.setGeometry(QtCore.QRect(240, 330, 51, 31))
self.spinBox_3.setObjectName("spinBox_3")
self.label_8 = QtWidgets.QLabel(self.centralwidget)
self.label_8.setGeometry(QtCore.QRect(330, 330, 41, 31))
self.label_8.setObjectName("label_8")
self.spinBox_4 = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox_4.setGeometry(QtCore.QRect(390, 330, 51, 31))
self.spinBox_4.setObjectName("spinBox_4")
self.label_9 = QtWidgets.QLabel(self.centralwidget)
self.label_9.setGeometry(QtCore.QRect(460, 410, 61, 61))
self.label_9.setObjectName("label_9")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 664, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

    self.retranslateUi(MainWindow)
    self.pushButton.clicked.connect(MainWindow.enter) # type: ignore
    QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.label.setText(_translate("MainWindow", "人生模拟器"))
    self.pushButton.setText(_translate("MainWindow", "开始"))
    self.label_2.setText(_translate("MainWindow", "设置人物寿命:"))
    self.label_3.setText(_translate("MainWindow", "设置人物姓名:"))
    self.label_4.setText(_translate("MainWindow", "设置人物类型:"))
    self.comboBox.setItemText(0, _translate("MainWindow", "贵族"))
    self.comboBox.setItemText(1, _translate("MainWindow", "中产"))
    self.comboBox.setItemText(2, _translate("MainWindow", "底层"))
    self.label_5.setText(_translate("MainWindow", "设置时代:"))
    self.comboBox_2.setItemText(0, _translate("MainWindow", "普通时代"))
    self.comboBox_2.setItemText(1, _translate("MainWindow", "魔法时代"))
    self.comboBox_2.setItemText(2, _translate("MainWindow", "科幻时代"))
    self.label_6.setText(_translate("MainWindow", "能力:"))
    self.label_7.setText(_translate("MainWindow", "运气:"))
    self.label_8.setText(_translate("MainWindow", "体力:"))
    self.label_9.setText(_translate("MainWindow", "称号"))

`
逻辑文件:

`
import sys,random
from PyQt5.QtWidgets import *
from uach import *

class My(QMainWindow,Ui_MainWindow):
def init(self,parent=None):
super(My, self).init(parent)
self.setupUi(self)

def enter(self):
    a1,a2,a3,a4,b3,c3,pl = self.steady()
    self.spinBox_2.setMaximum(20)
    self.spinBox_3.setMaximum(20)
    self.spinBox_4.setMaximum(20)

    y = self.lineEdit.text()
    if (not y.isalpha()) or (len(y) > 6):
        QMessageBox.about(self,'喂!',y+'不是一个正常的姓名')
        return
    x = self.spinBox.value()
    if x == 0:
        QMessageBox.about(self,'注意',y+'死于没有岁数')
        return

    z1 = self.spinBox_2.value()
    z2 = self.spinBox_3.value()
    z3 = self.spinBox_4.value()
    if z1+z2+z3 > 30:
        QMessageBox.about(self,'注意','点数之和不得超过30')
        return
    global trans
    QMessageBox.about(self,'0岁',y+'出生了')
    for i in range(1,x):
        if 1 <= i <= 12:
            QMessageBox.about(self,(str(i)+'岁的'+y)
                              ,a1[int(random.random()*len(a1))])
        elif 12 < i < 22:
            QMessageBox.about(self, (str(i) + '岁的' + y),
                              a2[int(random.random()*len(a2))])
            if i == 21:
                ite1, ok1 = QInputDialog.getItem(self, y, '你的选择',
                                ('创业', '打工', '摆烂'), 0, False)
                if ite1 and ok1:
                    if ite1 == '创业':
                        trans = 10
                    elif ite1 == '打工':
                        trans = 20
                    else:
                        trans = 30
                else:
                    trans = 30
        elif 22 <= i <= 55:
            if trans == 10:
                QMessageBox.about(self, (str(i) + '岁的' + y)
                              , a3[int(random.random()*len(a3))])
            elif trans == 20:
                QMessageBox.about(self, (str(i) + '岁的' + y)
                              , b3[int(random.random()*len(b3))])
            else:
                QMessageBox.about(self, (str(i) + '岁的' + y)
                       , c3[int(random.random() * len(c3))])
        else:
            QMessageBox.about(self, (str(i) + '岁的' + y)
                              , a4[int(random.random()*len(a4))])
    QMessageBox.about(self,(str(x)+'岁的'+y), y+'去世了')
    self.label_9.setText(pl[int(random.random()*len(pl))])

`

一个只是被调用的静态函数

`
def steady(self):
good = ["很好", "真不赖", "简直完美", "棒棒哒", "蛮好", "还行", "中等", "不错"
, "恶劣", "一般",
"挺优秀", "很差", "太烂了", "还凑合", "很糟糕", "还能接受", "难以忍受"]
fp = ["一直", "总是", "经常", "偶尔"]
adj = ["挑食", "矫情", "内向", "乖巧", "沉默", "活泼", "调皮", "优秀", "奇怪"]
adv = ["非常", "比较", "有点", "尤其", "很"]
like = ["像一朵巨大的奇葩", "是一根可爱的棒棒糖", "如同一只走狗", "宛如一颗库柏",
"跟个大仙一样",
"及其不好惹", "是个绅士"]
adj2 = ["凶横的", "可爱的", "亲爱的", "优秀的", "有钱的", "窘迫的", "憨态可掬的",
"中肯的",
"一针见血的", "不要脸的"]
q = ["智商", "情商", "德商", "财商", "美商", "体育能力"]
subj = ["化学", "物理", "生物", "美术", "音乐", "体育", "语文", "数学",
"英语", "地理",
"历史"]
hobby = ["滑雪", "踢足球", "打篮球", "垫排球", "打棒球", "投掷铅球",
"丢沙包", "耍滑板",
"瞎起哄",
"干神秘的事情", "玩水"]
adj3 = ["兴奋", "快活", "自豪", "自负", "搞笑", "神秘", "伤心", "自卑",
"无聊", "劳累", "害怕",
"焦虑"]
time = ["早上", "下午", "傍晚", "中午"]
place = ["竹林里", "房间里", "别人家里", "平坦的地上", "沙滩上", "小河边", "树林里"]
adj4 = ["帮博士跑腿的", "整天996的", "整天007的", "受排斥的", "抑郁难受的",
"兴高彩烈的",
"壮志难酬的"]
n = ["鲜花", "戒指", "红包", "项链", "一个故事", "%……&YFvf", "一首诗"]
pl = ["重庆", "北京", "", "安徽宏村", "安徽黄山", "福建武夷山", "福建霞浦", "鸣沙山",
"开平碉楼",
"广西阳朔", "贵州黄果树瀑布", "月牙泉", "一块附魔书", "世外桃源", "洱海月湿地公园",
"小普陀", "岩石园"]
thing = ["一个游泳池", "一个大别墅", "岩石园", "一块翡翠", "一包辣条", "一间卧室",
"一克反物质", "化学药剂"]
chem = ["一瓶双氧水", "1kg弱酸", "200g强碱", "一个高能粒子", "神秘的UFO"]
anim = ["猛虎", "鳄鱼", "狮子", "棕熊", "熊猫"]
body = ["腿脚", "肾脏", "肝脏", "脾胃", "心脏", "记忆", "平衡", "行为", "性格",
"脾气", "皮肤", "眼睛", "耳朵"]

    a1 = []
    a2 = []
    a3 = []
    b3 = []
    c3 = []
    a4 = []
    for k in good:
        for kk in fp:
            a1.append("你在学校" + kk + k + ",哈哈哈!")
            a1.append("你在家里" + kk + k + ",嘻嘻~")
    for k in adj:
        for kk in adv:
            a1.append("老师说你" + kk + k + ",啧!")
    for k in like:
        for kk in adj2:
            a1.append(kk + "同学说你" + k + ",嘿嘿!")

    for k in q:
        for kk in adv:
            a1.append("别人感觉你" + k + kk + "一般!")
            a1.append("别人觉得你" + k + kk + "好~")

    a1.append("你在晚上能看到一个黑影在房间里穿梭")
    for k in subj:
        a2.append("你反感" + k + "老师,所以翘他的课")

    for k in hobby:
        for kk in good:
            a2.append("你课余时间" + k + ",成绩" + kk + "了~")

    for k in adj3:
        for kk in good:
            a2.append("你开始变得" + k + ",并感到自己未来会" + kk + "~")

    for k in subj:
            a2.append("你最近喜欢" + k + ",想选xx专业")

    for k in time:
        for kk in place:
            for k3 in hobby:
                a2.append(k + "你在" + kk + k3)
    a2.append("你和隔壁班同学干了起来")
    a2.append("你一直能看到那个耀眼的UFO")
    a2.append("你聆听外星人的谈话,可啥也没听懂")
    a2.append("你有一种不详的预感,可你又是无神论者")
    a2.append("你在期待那个神秘人!")

    for k in subj:
        a3.append("你做了" + k + "相关的工作")

    for k in adj4:
        for kk in adj3:
            b3.append("你成为了" + k + "打工人,感到" + kk)
    for k in adj3:
        a3.append("你准备创业,一开始" + k)
    for k2 in fp:
        for k3 in good:
            a3.append("你自主创业,结果" + k2 + k3)

    for k in n:
        a3.append("你结婚了,送给配偶" + k)
        b3.append("你结婚了,送给配偶" + k)
        c3.append("你结婚了,送给配偶" + k)

    for k in place:
        for k2 in time:
            c3.append("在一个" + k2 + "你们去" + k + "度假")
            a3.append("在一个" + k2 + "你们把家搬到了" + k)

    for k in place:
        c3.append("你参加了别人举办的,去" + k + "的探险活动")

    for k in thing:
        a3.append("你买了" + k)
    for k in like:
        a3.append("单位的人议论你" + k)
        b3.append('单位人议论你'+k)

    for k in time:
        for k2 in time:
            for k3 in chem:
                a3.append("你做实验从" + k + "做到" + k2 + "用了" + k3)
                b3.append("你做实验从" + k + "做到" + k2 + "用了" + k3)

    for k in anim:
        for k2 in fp:
            a3.append("你在外面" + k2 + "瞥见" + k + ",它在瞌睡")
            a3.append("你外出的时候" + k2 + "看到" + k + ",它和同伴玩耍")
            b3.append("你隐约" + k2 + "察觉一只小" + k + ",它踽踽独行很可怜")
            a3.append("你做梦" + k2 + "梦到" + k + ",它试图把你逼向绝路")
    c3.append("karl遮住了你的眼睛,但你明显看见了一个UFO")
    c3.append("你遇到了一个小鬼:不给糖,就捣蛋")
    c3.append("道路是曲折的,前途是光明的")

    for k in hobby:
        a4.append("你退休了,所以整天" + k)

    for k in subj:
        for k2 in adj3:
            a4.append("你思考" + k + "但感到" + k2)

    for k in q:
        for k2 in good:
            a4.append("你的" + k + "变得" + k2)

    for k in body:
        for k2 in good:
            a4.append("你的" + k + "变得" + k2)
    for k in hobby:
        a4.append("你又想起了儿时的" + k)
        a4.append("你想到了壮年的" + k)

    a4.append("楼上那位说家不远处有猛兽出没")
    a4.append("#……&*T-G-J-B-J-K-B-J-H-I-##)(**&*&")
    random.shuffle(a1)
    random.shuffle(a2)
    random.shuffle(a3)
    random.shuffle(a4)
    random.shuffle(b3)
    random.shuffle(c3)
    return a1,a2,a3,a4,b3,c3,pl

`

if name == 'main':
app = QApplication(sys.argv)
#对象数组
n = int(input('创建几个窗口:'))
m = [My() for _ in range(n+1)]
for i in range(n):
m[i].show()
sys.exit(app.exec())