这是初级版本的人生模拟器
可以控制人物年龄和人物姓名,来模拟这个人的一生
通过QMessage。about来实现这个人的一生
`
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(797, 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(220, 240, 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")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 797, 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", "设置人物姓名:"))
单击按钮只绑定了一个槽函数enter
`
mport 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):
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 = []
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:
a3.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)
for k in place:
for k2 in time:
a3.append("在一个" + k2 + "你们去" + k + "度假")
a3.append("在一个" + k2 + "你们把家搬到了" + k)
for k in place:
a3.append("你参加了别人举办的,去" + k + "的探险活动")
for k in thing:
a3.append("你买了" + k)
for k in like:
a3.append("单位的人议论你" + k)
for k in time:
for k2 in time:
for k3 in chem:
a3.append("你做实验从" + k + "做到" + k2 + "用了" + k3)
for k in anim:
for k2 in fp:
a3.append("你在外面" + k2 + "瞥见" + k + ",它在瞌睡")
a3.append("你外出的时候" + k2 + "看到" + k + ",它和同伴玩耍")
a3.append("你隐约" + k2 + "察觉一只小" + k + ",它踽踽独行很可怜")
a3.append("你做梦" + k2 + "梦到" + k + ",它试图把你逼向绝路")
a3.append("karl遮住了你的眼睛,但你明显看见了一个UFO")
a3.append("你遇到了一个小鬼:不给糖,就捣蛋")
a3.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)
`
`
`
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
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))])
elif 22 <= i <= 55:
QMessageBox.about(self, (str(i) + '岁的' + y)
, a3[int(random.random()len(a3))])
else:
QMessageBox.about(self, (str(i) + '岁的' + y)
, a4[int(random.random()len(a4))])
QMessageBox.about(self,(str(x)+'岁的'+y),y+'去世了')
if name == 'main':
app = QApplication(sys.argv)
#对象数组
n = int(input('创建几个窗口:'))
m = [My() for _ in range(n+1)]
for i in range(1,n+1):
m[i].show()
sys.exit(app.exec())
`