#2
东海ECS2023-03-11 11:39
程序代码: # -*- coding: utf-8 -*- from PyQt5 import QtWidgets, QtGui, QtCore from PyQt5.QtWidgets import QMessageBox from PyQt5.QtWidgets import QStatusBar import MainMenu # 这是窗体文件 import sys import time import ctypes import inspect import random import threading import Bag import Store import Study import work import FindWork class MainMenuWindow(QtWidgets.QMainWindow, MainMenu.Ui_MainMenu): def __init__(self): super(MainMenuWindow, self).__init__() self.setupUi(self) # 将 QPushButton 控件的 clicked 信号连接到对应的方法上 self.workButton.clicked.connect(self.work) self.goToSchoolButton.clicked.connect(self.goToSchool) self.showButton.clicked.connect(self.show_) self.studyButton.clicked.connect(self.study) self.openBagButton.clicked.connect(self.openBag) self.goToStoreButton.clicked.connect(self.goToStore) self.statusLabel = QtWidgets.QLabel() self.statusbar.addWidget(self.statusLabel) self.statusLabel.setText('年龄:0 | 生病:False | 工作: | 最近剧情:') self.workButton.hide() def work(self): work.init() def goToSchool(self): school.init() def show_(self): player.show() def study(self): player.study() def openBag(self): player.openBag() def goToStore(self): store.init() class BagWindow(QtWidgets.QMainWindow, Bag.Ui_BagWindow): def __init__(self): super(BagWindow, self).__init__() self.setupUi(self) self.exitButton.clicked.connect(self.exit) self.strongButton.clicked.connect(self.doStrong) self.faceButton.clicked.connect(self.doFace) self.medicinalButton.clicked.connect(self.doMedicinal) self.lotteryTicketButton.clicked.connect(self.doLotteryTicket) self.iqButton.clicked.connect(self.doIq) def exit(self): self.hide() def doStrong(self): player.doBag.doStrong() def doIq(self): player.doBag.doIq() def doFace(self): player.doBag.doFace() def doMedicinal(self): player.doBag.doMedicinal() def doLotteryTicket(self): player.doBag.doLotteryTicket() class StoreWindow(QtWidgets.QMainWindow, Store.Ui_StoreWindow): def __init__(self): super(StoreWindow, self).__init__() self.setupUi(self) self.exitButton.clicked.connect(self.exit) self.strongButton.clicked.connect(self.buyStrong) self.iqButton.clicked.connect(self.buyIq) self.faceButton.clicked.connect(self.buyFace) self.medicinalButton.clicked.connect(self.buyMedicinal) self.lotteryTicketButton.clicked.connect(self.buyLotteryTicket) def exit(self): self.hide() def buyStrong(self): store.buyStrong() def buyIq(self): store.buyIq() def buyFace(self): store.buyFace() def buyMedicinal(self): store.buyMedicinal() def buyLotteryTicket(self): store.buyLotteryTicket() class StudyWindow(QtWidgets.QMainWindow, Study.Ui_StudyWindow): def __init__(self): super(StudyWindow, self).__init__() self.setupUi(self) self.checkButton.clicked.connect(self.finish) self.lineEdit_1.editingFinished.connect(self.finish) def finish(self): if self.a + self.b == eval(self.lineEdit_1.text()): player.studyFinish(True) else: player.studyFinish(False) def start(self, a, b): self.a = a self.b = b self.lcdNumber_1.setProperty('value', a) self.lcdNumber_2.setProperty('value', b) class WorkWindow(QtWidgets.QMainWindow, work.Ui_WorkWindow): def __init__(self): super(WorkWindow, self).__init__() self.setupUi(self) class FindWorkWindow(QtWidgets.QMainWindow, FindWork.Ui_FindWorkWindow): def __init__(self): super(FindWorkWindow, self).__init__() self.setupUi(self) class Player: """ 定义一个玩家类 """ # 颜值 face = 0 # 智力 iq = 0 # 体质 strong = 0 # 家境 home = 0 # 性别,true男false女 sex = False # 身份 identity = '' # 背包字典 bag = { '强壮药水': 0, '智力药水': 0, '美容药水': 0, '药物': 0, '彩票': 0 } # 岁数 age = 0 # 知识 knowledge = 0 doBag = 0 point = 0 # 钱 dollars = 0 # 是否在学校 isInSchool = False # 人缘 popularity = 10 # 学校等级 schoolGrade = 1 # 线程 thread = threading.Thread() # 工作 work = '' # 是否生病 isSicking = False # 最近发生的事情 plots = '' def __init__(self): """初始化属性""" self.face = random.randint(1, 10) self.iq = random.randint(1, 10) self.strong = random.randint(1, 10) self.home = random.randint(1, 10) if random.randint(1, 2) == 1: self.sex = True else: self.sex = False self.point = random.randint(1, 6) self.identiyJudgment() self.doBag = self.DoBag() def identiyJudgment(self): """身份判断""" # self.identity = '' if self.home == 10: self.identity = '出生在帝都,父母是世界首富.' self.dollars += random.randint(100, 10000000) elif 7 <= self.home <= 9: if self.point == 1: self.identity = '出生在一线城市,父母是医生.' self.face += 2 self.dollars += random.randint(10, 200) elif self.point == 2: self.identity = '出生在一线城市,父母是资深程序员.' self.iq += 2 self.dollars += random.randint(100, 10000) else: self.identity = '出生在一线城市,父母是健身教练.' self.strong += 3 self.face += 1 self.iq -= 1 self.dollars += random.randint(30, 300) elif 4 <= self.home <= 6: if self.point == 1: self.identity = '出生在三线城市,父母是企业管理.' self.iq += 1 self.dollars += random.randint(50, 10000) elif self.point == 2: self.identity = '出生在三线城市,父母是小学老师.' self.iq += 1 self.dollars += random.randint(10, 100) else: self.identity = '出生在三线城市,父母是自己开店做生意.' self.home += 1 self.dollars += random.randint(100, 1000) else: if self.point == 1: self.identity = '出生在农村,父母是农民.' self.strong += 2 self.face -= 1 self.dollars += random.randint(3, 10) elif self.point == 2: self.identity = '出生在山里,父母是猎人.' self.strong += 2 self.home -= 1 self.face -= 1 self.dollars += random.randint(5, 20) else: self.identity = '你出生在小镇上,父母是镇长.' self.face += 1 self.home += 1 self.dollars += random.randint(80, 100) def show(self): """显示属性""" showMessage(mainMenuWindow, '属性', f''' 颜值:{self.face} 智力:{self.iq} 体质:{self.strong} 家境:{self.home} 性别:{sex} 身份:{self.identity} 年龄:{self.age} 知识:{self.knowledge} ''') def study(self): """学习""" studyWindow.show() studyWindow.lineEdit_1.setText('') studyWindow.start(random.randint(9999, 100000), random.randint(9999, 100000)) def studyFinish(self, bools): if bools: if self.isInSchool: self.knowledge += self.iq * 2 showMessage(studyWindow, '恭喜', f'良好的学习环境使你事半功倍,知识加{self.iq * 2}') studyWindow.hide() else: self.knowledge += self.iq showMessage(studyWindow, '恭喜', f'答对了,知识加{self.iq}') studyWindow.hide() else: showMessage(studyWindow, '遗憾', '很遗憾,没答对') studyWindow.hide() def openBag(self): """打开背包""" player.isInSchool = False bagWindow.show() bagWindow.strongLabel.setText('数量:' + str(self.bag['强壮药水'])) bagWindow.iqLabel.setText('数量:' + str(self.bag['智力药水'])) bagWindow.faceLabel.setText('数量:' + str(self.bag['美容药水'])) bagWindow.medicinalLabel.setText('数量:' + str(self.bag['药物'])) bagWindow.lotteryTicketLabel.setText('数量:' + str(self.bag['彩票'])) def growUp(self): """成长""" while True: # 10秒成长一岁 time.sleep(10) self.age += 1 mainMenuWindow.statusLabel.setText(f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') if self.age == 12: print('你进入了青春期,身体变得强壮了,体质加二') self.strong += 2 elif self.age == 30: print('三十而立,颜值,智力,体质各加1') self.face += 1 self.iq += 1 self.strong += 1 self.stand() elif self.age == 40: print('四十而不惑,中年时期开始,智力加2') self.iq += 2 elif self.age == 50: print('五十而知天命,颜值,体质减1') self.face -= 1 self.strong -= 1 elif self.age == 60: print('六十而耳顺,老年时期开始,颜值,体质,智力减1') self.face -= 1 self.strong -= 1 self.iq -= 1 elif self.age == 70: print('七十而从心所欲,不逾矩.颜值,体质,智力减1') self.face -= 1 self.strong -= 1 self.iq -= 1 elif self.age == 80: print('已到耄耋时期.颜值,体质,智力减1') self.face -= 1 self.strong -= 1 self.iq -= 1 elif self.age == 90: print('耄耋时期.颜值,体质,智力减1') self.face -= 1 self.strong -= 1 self.iq -= 1 elif self.age == 100: print('已到期颐之年.颜值,体质,智力减1') self.face -= 1 self.strong -= 1 self.iq -= 1 def sick(self, sick): """生病""" player.isInSchool = False print('生病中...') print(f'每3秒体质减{sick // 2},请及时救治.') self.isSicking = True mainMenuWindow.statusLabel.setText(f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') def sicking(): while True: self.strong -= sick // 2 print(f'生病中,体质减{sick // 2}') time.sleep(3) self.thread = threading.Thread(target = sicking) self.thread.start() def plot(self): """剧情""" while True: time.sleep(random.randint(5, 20)) point = random.randint(1, 6) if self.sex and point == 1 and self.home <= 3 and self.age <= 5: print('你的家里人重男轻女思想非常严重,把你丢弃了.') self.plots = '你的家里人重男轻女思想非常严重,把你丢弃了.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') print("游戏结束.") sys.exit() elif self.strong <= 8: print('你生了一场病') self.plots = '你生了一场病' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') a = random.randint(1, 5) self.sick(a) elif self.face <= 4 and self.age <= 15: if point <= 2: print('你长的太丑了,别的小朋友不和你一起玩.') self.plots = '你长的太丑了,别的小朋友不和你一起玩.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.popularity -= 1 if self.iq <= 5 and point == 2: if self.strong >= 8: print('你和别的小朋友打架.') self.plots = '你和别的小朋友打架.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.popularity -= 1 self.iq -= 1 self.strong -= 1 else: print('你经常被别的小朋友欺负.') self.plots = '你经常被别的小朋友欺负.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.strong -= 1 elif self.iq <= 4: print('你有点笨.') if self.home >= 8 and self.age >= 6: print('你的父母把你送到更好的学校学习.') self.plots = '你的父母把你送到更好的学校学习.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.iq += 1 self.schoolGrade += 1 elif 4 <= self.home <= 7: if self.sex: print('你的父母鼓励你多运动,争取成为运动健将.') self.plots = '你的父母鼓励你多运动,争取成为运动健将.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.strong += 1 else: print('你的父母鼓励你多打扮自己.') self.plots = '你的父母鼓励你多打扮自己.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') self.face += 1 else: pass else: print('这次没有特别的事情发生.') self.plots = '这次没有特别的事情发生.' mainMenuWindow.statusLabel.setText( f'年龄:{self.age} | 生病:{self.isSicking} | 工作:{self.work} | 最近剧情:{self.plots}') def stand(self): """三十而立""" work.findWork() class DoBag: """ 定义一个背包事件类 """ def doStrong(self): if player.bag['强壮药水'] >= 1: player.strong += 1 player.bag['强壮药水'] -= 1 bagWindow.strongLabel.setText('数量:' + str(player.bag['强壮药水'])) else: showMessage(bagWindow, '错误', ' 强壮药水 的数量似乎不够哦!') def doIq(self): if player.bag['智力药水'] >= 1: player.iq += 1 player.bag['智力药水'] -= 1 bagWindow.iqLabel.setText('数量:' + str(player.bag['智力药水'])) else: showMessage(bagWindow, '错误', ' 智力药水 的数量似乎不够哦!') def doFace(self): if player.bag['美容药水'] >= 1: player.face += 1 player.bag['美容药水'] -= 1 bagWindow.faceLabel.setText('数量:' + str(player.bag['美容药水'])) else: showMessage(bagWindow, '错误', ' 美容药水 的数量似乎不够哦!') def doMedicinal(self): if player.bag['药物'] >= 1: try: stop_thread(player.thread) except: showMessage(bagWindow, '错误', '你似乎没生病哦!') else: player.bag['药物'] -= 1 showMessage(bagWindow, '成功', '医疗成功!') player.isSicking = False else: showMessage(bagWindow, '错误', ' 药物 的数量似乎不够哦!') def doLotteryTicket(self): if player.bag['彩票'] >= 1: a = random.randint(1, 10) # 如果抽中6,得大奖 if a == 6: player.dollars += 5000000 showMessage(bagWindow, '恭喜', '恭喜你获得500W大奖!') # 如果抽中2,得小奖 if a == 2: player.dollars += 500 showMessage(bagWindow, '恭喜', '恭喜你获得500奖励!') if a != 6 and a != 2: showMessage(bagWindow, '遗憾', '很遗憾,没中奖.') player.bag['彩票'] -= 1 else: showMessage(bagWindow, '错误', ' 彩票 的数量似乎不够哦!') class Store: """ 定义一个商店类 """ # 商品字典 wares = {} def __init__(self): self.wares = { '强壮药水': 20, '智力药水': 20, '美容药水': 20, '药物': 20, '彩票': 20 } def init(self): player.isInSchool = False storeWindow.show() storeWindow.strongLabel.setText('价格:' + str(self.wares['强壮药水'])) storeWindow.iqLabel.setText('价格:' + str(self.wares['智力药水'])) storeWindow.faceLabel.setText('价格:' + str(self.wares['美容药水'])) storeWindow.medicinalLabel.setText('价格:' + str(self.wares['药物'])) storeWindow.lotteryTicketLabel.setText('价格:' + str(self.wares['彩票'])) storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) def buyStrong(self): if showMessage(storeWindow, '提示', '是否购买 强壮药水 ?', True): if player.dollars >= self.wares['强壮药水']: try: player.dollars -= self.wares['强壮药水'] player.bag['强壮药水'] += 1 storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) except: showMessage(storeWindow, '错误', '购买失败!') else: showMessage(storeWindow, '成功', '购买成功!') else: showMessage(storeWindow, '失败', '钱数不够,购买失败!') def buyIq(self): if showMessage(storeWindow, '提示', '是否购买 智力药水 ?', True): if player.dollars >= self.wares['智力药水']: try: player.dollars -= self.wares['智力药水'] player.bag['智力药水'] += 1 storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) except: showMessage(storeWindow, '错误', '购买失败!') else: showMessage(storeWindow, '成功', '购买成功!') else: showMessage(storeWindow, '失败', '钱数不够,购买失败!') def buyFace(self): if showMessage(storeWindow, '提示', '是否购买 美容药水 ?', True): if player.dollars >= self.wares['美容药水']: try: player.dollars -= self.wares['美容药水'] player.bag['美容药水'] += 1 storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) except: showMessage(storeWindow, '错误', '购买失败!') else: showMessage(storeWindow, '成功', '购买成功!') else: showMessage(storeWindow, '失败', '钱数不够,购买失败!') def buyMedicinal(self): if showMessage(storeWindow, '提示', '是否购买 药物 ?', True): if player.dollars >= self.wares['药物']: try: player.dollars -= self.wares['药物'] player.bag['药物'] += 1 storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) except: showMessage(storeWindow, '错误', '购买失败!') else: showMessage(storeWindow, '成功', '购买成功!') else: showMessage(storeWindow, '失败', '钱数不够,购买失败!') def buyLotteryTicket(self): if showMessage(storeWindow, '提示', '是否购买 彩票 ?', True): if player.dollars >= self.wares['彩票']: try: player.dollars -= self.wares['彩票'] player.bag['彩票'] += 1 storeWindow.DollarsLabel.setText('您的钱数:' + str(player.dollars)) except: showMessage(storeWindow, '错误', '购买失败!') else: showMessage(storeWindow, '成功', '购买成功!') else: showMessage(storeWindow, '失败', '钱数不够,购买失败!') class School: """ 定义一个学校类 """ def __init__(self): pass def init(self): showMessage(mainMenuWindow, '提示', '你进入了学校,这里学习氛围好,学习事半功倍') player.isInSchool = True player.study() class Work: """ 定义一个工作类 """ def __init__(self): pass def findWork(self): pass def init(self): pass def showMessage(window, txt, showTxt, YexOrNo = False): """显示窗体, 标题, 显示文本, 是否判断""" if YexOrNo: a = QMessageBox.information(window, txt, showTxt, QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if a == QMessageBox.Yes: return True else: return False else: QMessageBox.information(window, txt, showTxt) def _async_raise(tid, exctype): if not inspect.isclass(exctype): exctype = type(exctype) res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("Invalid tid") elif res != 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) raise RuntimeError("PyThreadState_SetAsyncExc failed") def stop_thread(thread): _async_raise(thread.ident, SystemExit) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) player = Player() school = School() store = Store() work = Work() mainMenuWindow = MainMenuWindow() mainMenuWindow.show() bagWindow = BagWindow() storeWindow = StoreWindow() studyWindow = StudyWindow() workWindow = WorkWindow() findWorkWindow = FindWorkWindow() sex = '男' if player.sex: pass else: sex = '女' showMessage(mainMenuWindow, '提示', '作者:东海ECS 版权我的,大家可以随便用') showMessage(mainMenuWindow, '提示', f''' 颜值:{player.face} 智力:{player.iq} 体质:{player.strong} 家境:{player.home} 性别:{sex} 身份:{player.identity} ''') thread = [threading.Thread(target = player.growUp), threading.Thread(target = player.plot)] for i in thread: i.start() sys.exit(app.exec_()) |
人生重开模拟器(GUI版)2.1.6
这是我原创的一个小游戏,以后会不断升级
游戏截图:
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
注意:
运行依赖库:
程序代码:
1.PyQt5
2.ctypes
3.inspect
运行方法:
1.解压,运行begins文件:
只有本站会员才能查看附件,请 登录
就可以了.
下载:
只有本站会员才能查看附件,请 登录
附代码
程序代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Bag.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_BagWindow(object):
def setupUi(self, BagWindow):
BagWindow.setObjectName("BagWindow")
BagWindow.resize(274, 275)
self.centralwidget = QtWidgets.QWidget(BagWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(50, 10, 171, 31))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(18)
font.setBold(False)
font.setWeight(50)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.formLayoutWidget.setGeometry(QtCore.QRect(30, 50, 211, 171))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
self.formLayout.setRowWrapPolicy(QtWidgets.QFormLayout.DontWrapRows)
self.formLayout.setLabelAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.strongButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.strongButton.setObjectName("strongButton")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.strongButton)
self.strongLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.strongLabel.setFont(font)
self.strongLabel.setObjectName("strongLabel")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.strongLabel)
self.iqButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.iqButton.setObjectName("iqButton")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.iqButton)
self.iqLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.iqLabel.setFont(font)
self.iqLabel.setObjectName("iqLabel")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.iqLabel)
self.faceButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.faceButton.setObjectName("faceButton")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.faceButton)
self.faceLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.faceLabel.setFont(font)
self.faceLabel.setObjectName("faceLabel")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.faceLabel)
self.medicinalButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.medicinalButton.setObjectName("medicinalButton")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.medicinalButton)
self.medicinalLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.medicinalLabel.setFont(font)
self.medicinalLabel.setObjectName("medicinalLabel")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.medicinalLabel)
self.lotteryTicketLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.lotteryTicketLabel.setFont(font)
self.lotteryTicketLabel.setObjectName("lotteryTicketLabel")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.lotteryTicketLabel)
self.lotteryTicketButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.lotteryTicketButton.setObjectName("lotteryTicketButton")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.lotteryTicketButton)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(170, 220, 93, 28))
self.exitButton.setObjectName("exitButton")
BagWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(BagWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 274, 26))
self.menubar.setObjectName("menubar")
BagWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(BagWindow)
self.statusbar.setObjectName("statusbar")
BagWindow.setStatusBar(self.statusbar)
self.retranslateUi(BagWindow)
QtCore.QMetaObject.connectSlotsByName(BagWindow)
def retranslateUi(self, BagWindow):
_translate = QtCore.QCoreApplication.translate
BagWindow.setWindowTitle(_translate("BagWindow", "背包"))
self.label.setText(_translate("BagWindow", "背包"))
self.strongButton.setText(_translate("BagWindow", "强壮药水"))
self.strongLabel.setText(_translate("BagWindow", "数量:"))
self.iqButton.setText(_translate("BagWindow", "智力药水"))
self.iqLabel.setText(_translate("BagWindow", "数量:"))
self.faceButton.setText(_translate("BagWindow", "美容药水"))
self.faceLabel.setText(_translate("BagWindow", "数量:"))
self.medicinalButton.setText(_translate("BagWindow", "药物"))
self.medicinalLabel.setText(_translate("BagWindow", "数量:"))
self.lotteryTicketLabel.setText(_translate("BagWindow", "数量:"))
self.lotteryTicketButton.setText(_translate("BagWindow", "彩票"))
self.exitButton.setText(_translate("BagWindow", "退出"))
程序代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'MainMenu.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtWidgets import QMainWindow
class Ui_MainMenu(object):
def setupUi(self, MainMenu):
MainMenu.setObjectName("MainMenu")
MainMenu.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainMenu)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(0, 0, 801, 271))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(":/png/resource Files/人生重开.png"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 280, 781, 261))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.workButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.workButton.setObjectName("workButton")
self.verticalLayout.addWidget(self.workButton)
self.goToSchoolButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.goToSchoolButton.setObjectName("goToSchoolButton")
self.verticalLayout.addWidget(self.goToSchoolButton)
self.showButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.showButton.setObjectName("showButton")
self.verticalLayout.addWidget(self.showButton)
self.studyButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.studyButton.setObjectName("studyButton")
self.verticalLayout.addWidget(self.studyButton)
self.openBagButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.openBagButton.setObjectName("openBagButton")
self.verticalLayout.addWidget(self.openBagButton)
self.goToStoreButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.goToStoreButton.setObjectName("goToStoreButton")
self.verticalLayout.addWidget(self.goToStoreButton)
MainMenu.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainMenu)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainMenu.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainMenu)
self.statusbar.setObjectName("statusbar")
MainMenu.setStatusBar(self.statusbar)
self.retranslateUi(MainMenu)
QtCore.QMetaObject.connectSlotsByName(MainMenu)
def retranslateUi(self, MainMenu):
_translate = QtCore.QCoreApplication.translate
MainMenu.setWindowTitle(_translate("MainMenu", "主界面"))
self.workButton.setText(_translate("MainMenu", "工作"))
self.goToSchoolButton.setText(_translate("MainMenu", "去学校"))
self.showButton.setText(_translate("MainMenu", "显示属性"))
self.studyButton.setText(_translate("MainMenu", "学习"))
self.openBagButton.setText(_translate("MainMenu", "打开背包"))
self.goToStoreButton.setText(_translate("MainMenu", "去商店"))
sys.path.append(r'qrc Files')
import MainMenuQrc_rc
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow() # 创建窗体对象
ui = Ui_MainMenu() # 创建pyqt设计的窗体对象
ui.setupUi(MainWindow) # 调用PyQt窗体的方法对对象进行初始化设置
MainWindow.show() # 显示窗体
sys.exit(app.exec_()) # 程序关闭时退出进程
程序代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Store.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_StoreWindow(object):
def setupUi(self, StoreWindow):
StoreWindow.setObjectName("StoreWindow")
StoreWindow.resize(260, 292)
self.centralwidget = QtWidgets.QWidget(StoreWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(30, 10, 191, 41))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.formLayoutWidget.setGeometry(QtCore.QRect(30, 60, 191, 171))
self.formLayoutWidget.setObjectName("formLayoutWidget")
self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
self.formLayout.setContentsMargins(0, 0, 0, 0)
self.formLayout.setObjectName("formLayout")
self.strongButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.strongButton.setObjectName("strongButton")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.strongButton)
self.strongLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.strongLabel.setFont(font)
self.strongLabel.setObjectName("strongLabel")
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.strongLabel)
self.iqButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.iqButton.setObjectName("iqButton")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.iqButton)
self.iqLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.iqLabel.setFont(font)
self.iqLabel.setObjectName("iqLabel")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.iqLabel)
self.faceButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.faceButton.setObjectName("faceButton")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.faceButton)
self.faceLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.faceLabel.setFont(font)
self.faceLabel.setObjectName("faceLabel")
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.faceLabel)
self.medicinalButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.medicinalButton.setObjectName("medicinalButton")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.medicinalButton)
self.medicinalLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.medicinalLabel.setFont(font)
self.medicinalLabel.setObjectName("medicinalLabel")
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.medicinalLabel)
self.lotteryTicketButton = QtWidgets.QPushButton(self.formLayoutWidget)
self.lotteryTicketButton.setObjectName("lotteryTicketButton")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.lotteryTicketButton)
self.lotteryTicketLabel = QtWidgets.QLabel(self.formLayoutWidget)
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setBold(True)
font.setWeight(75)
self.lotteryTicketLabel.setFont(font)
self.lotteryTicketLabel.setObjectName("lotteryTicketLabel")
self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.lotteryTicketLabel)
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(160, 240, 93, 28))
self.exitButton.setObjectName("exitButton")
self.DollarsLabel = QtWidgets.QLabel(self.centralwidget)
self.DollarsLabel.setGeometry(QtCore.QRect(10, 240, 141, 31))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.DollarsLabel.setFont(font)
self.DollarsLabel.setObjectName("DollarsLabel")
StoreWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(StoreWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 260, 26))
self.menubar.setObjectName("menubar")
StoreWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(StoreWindow)
self.statusbar.setObjectName("statusbar")
StoreWindow.setStatusBar(self.statusbar)
self.retranslateUi(StoreWindow)
QtCore.QMetaObject.connectSlotsByName(StoreWindow)
def retranslateUi(self, StoreWindow):
_translate = QtCore.QCoreApplication.translate
StoreWindow.setWindowTitle(_translate("StoreWindow", "商店"))
self.label.setText(_translate("StoreWindow", "商店"))
self.strongButton.setText(_translate("StoreWindow", "强壮药水"))
self.strongLabel.setText(_translate("StoreWindow", "价格:"))
self.iqButton.setText(_translate("StoreWindow", "智力药水"))
self.iqLabel.setText(_translate("StoreWindow", "价格:"))
self.faceButton.setText(_translate("StoreWindow", "美容药水"))
self.faceLabel.setText(_translate("StoreWindow", "价格:"))
self.medicinalButton.setText(_translate("StoreWindow", "药物"))
self.medicinalLabel.setText(_translate("StoreWindow", "价格:"))
self.lotteryTicketButton.setText(_translate("StoreWindow", "彩票"))
self.lotteryTicketLabel.setText(_translate("StoreWindow", "价格:"))
self.exitButton.setText(_translate("StoreWindow", "退出"))
self.DollarsLabel.setText(_translate("StoreWindow", "您的钱数:"))
程序代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Study.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_StudyWindow(object):
def setupUi(self, StudyWindow):
StudyWindow.setObjectName("StudyWindow")
StudyWindow.resize(512, 117)
self.centralwidget = QtWidgets.QWidget(StudyWindow)
self.centralwidget.setObjectName("centralwidget")
self.lcdNumber_1 = QtWidgets.QLCDNumber(self.centralwidget)
self.lcdNumber_1.setGeometry(QtCore.QRect(20, 10, 101, 40))
self.lcdNumber_1.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.lcdNumber_1.setProperty("intValue", 123456)
self.lcdNumber_1.setObjectName("lcdNumber_1")
self.lcdNumber_2 = QtWidgets.QLCDNumber(self.centralwidget)
self.lcdNumber_2.setGeometry(QtCore.QRect(200, 10, 101, 40))
self.lcdNumber_2.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
self.lcdNumber_2.setProperty("intValue", 123456)
self.lcdNumber_2.setObjectName("lcdNumber_2")
self.label_1 = QtWidgets.QLabel(self.centralwidget)
self.label_1.setGeometry(QtCore.QRect(130, 10, 61, 41))
font = QtGui.QFont()
font.setFamily("Baskerville Old Face")
font.setPointSize(36)
font.setBold(False)
font.setWeight(50)
self.label_1.setFont(font)
self.label_1.setMidLineWidth(-4)
self.label_1.setAlignment(QtCore.Qt.AlignCenter)
self.label_1.setObjectName("label_1")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(320, 10, 61, 41))
font = QtGui.QFont()
font.setFamily("Baskerville Old Face")
font.setPointSize(36)
font.setBold(False)
font.setWeight(50)
self.label_2.setFont(font)
self.label_2.setMidLineWidth(-4)
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.lineEdit_1 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_1.setGeometry(QtCore.QRect(400, 10, 101, 41))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(20)
font.setBold(True)
font.setWeight(75)
self.lineEdit_1.setFont(font)
self.lineEdit_1.setText("")
self.lineEdit_1.setObjectName("lineEdit_1")
self.checkButton = QtWidgets.QPushButton(self.centralwidget)
self.checkButton.setGeometry(QtCore.QRect(410, 60, 93, 28))
self.checkButton.setObjectName("checkButton")
StudyWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(StudyWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 512, 26))
self.menubar.setObjectName("menubar")
StudyWindow.setMenuBar(self.menubar)
self.retranslateUi(StudyWindow)
QtCore.QMetaObject.connectSlotsByName(StudyWindow)
def retranslateUi(self, StudyWindow):
_translate = QtCore.QCoreApplication.translate
StudyWindow.setWindowTitle(_translate("StudyWindow", "学习"))
self.label_1.setText(_translate("StudyWindow", "+"))
self.label_2.setText(_translate("StudyWindow", "="))
self.checkButton.setText(_translate("StudyWindow", "检查"))
程序代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'work.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_WorkWindow(object):
def setupUi(self, WorkWindow):
WorkWindow.setObjectName("WorkWindow")
WorkWindow.resize(403, 244)
self.centralwidget = QtWidgets.QWidget(WorkWindow)
self.centralwidget.setObjectName("centralwidget")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(10, 10, 241, 141))
self.textEdit.setReadOnly(True)
self.textEdit.setPlaceholderText("")
self.textEdit.setObjectName("textEdit")
self.wookingButton = QtWidgets.QPushButton(self.centralwidget)
self.wookingButton.setGeometry(QtCore.QRect(260, 10, 121, 51))
self.wookingButton.setObjectName("wookingButton")
self.exitButton = QtWidgets.QPushButton(self.centralwidget)
self.exitButton.setGeometry(QtCore.QRect(10, 160, 93, 28))
self.exitButton.setObjectName("exitButton")
WorkWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(WorkWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 403, 26))
self.menubar.setObjectName("menubar")
WorkWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(WorkWindow)
self.statusbar.setObjectName("statusbar")
WorkWindow.setStatusBar(self.statusbar)
self.retranslateUi(WorkWindow)
QtCore.QMetaObject.connectSlotsByName(WorkWindow)
def retranslateUi(self, WorkWindow):
_translate = QtCore.QCoreApplication.translate
WorkWindow.setWindowTitle(_translate("WorkWindow", "工作"))
self.wookingButton.setText(_translate("WorkWindow", "工作"))
self.exitButton.setText(_translate("WorkWindow", "退出工作"))
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow() # 创建窗体对象
ui = Ui_WorkWindow() # 创建pyqt设计的窗体对象
ui.setupUi(MainWindow) # 调用PyQt窗体的方法对对象进行初始化设置
MainWindow.show() # 显示窗体
sys.exit(app.exec_()) # 程序关闭时退出进程
[此贴子已经被作者于2023-3-25 16:38编辑过]