之前给大家分享过灭霸命令GitHub地址:https://github.com/hotvulcan/Thanos.sh,本文使用Python+PyQt5实现灭霸响指,实现过程较简单,上效果图~
GUI实现代码如下:
# -*- coding: utf-8 -*- from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(766, 760) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.btn_start = QtWidgets.QPushButton(self.centralwidget) self.btn_start.setGeometry(QtCore.QRect(60, 10, 111, 101)) self.btn_start.setStyleSheet("background-color: rgba(255, 255, 255, 0);") self.btn_start.setText("") self.btn_start.setObjectName("btn_start") self.widget = QtWidgets.QWidget(self.centralwidget) self.widget.setGeometry(QtCore.QRect(60, 120, 631, 441)) self.widget.setObjectName("widget") self.verticalLayout = QtWidgets.QVBoxLayout(self.widget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.label_1 = QtWidgets.QLabel(self.widget) self.label_1.setAlignment(QtCore.Qt.AlignCenter) self.label_1.setObjectName("label_1") self.horizontalLayout.addWidget(self.label_1) self.label_2 = QtWidgets.QLabel(self.widget) self.label_2.setAlignment(QtCore.Qt.AlignCenter) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.label_3 = QtWidgets.QLabel(self.widget) self.label_3.setAlignment(QtCore.Qt.AlignCenter) self.label_3.setObjectName("label_3") self.horizontalLayout.addWidget(self.label_3) self.label_4 = QtWidgets.QLabel(self.widget) self.label_4.setAlignment(QtCore.Qt.AlignCenter) self.label_4.setObjectName("label_4") self.horizontalLayout.addWidget(self.label_4) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.label_5 = QtWidgets.QLabel(self.widget) self.label_5.setAlignment(QtCore.Qt.AlignCenter) self.label_5.setObjectName("label_5") self.horizontalLayout_2.addWidget(self.label_5) self.label_6 = QtWidgets.QLabel(self.widget) self.label_6.setAlignment(QtCore.Qt.AlignCenter) self.label_6.setObjectName("label_6") self.horizontalLayout_2.addWidget(self.label_6) self.label_7 = QtWidgets.QLabel(self.widget) self.label_7.setAlignment(QtCore.Qt.AlignCenter) self.label_7.setObjectName("label_7") self.horizontalLayout_2.addWidget(self.label_7) self.label_8 = QtWidgets.QLabel(self.widget) self.label_8.setAlignment(QtCore.Qt.AlignCenter) self.label_8.setObjectName("label_8") self.horizontalLayout_2.addWidget(self.label_8) self.verticalLayout.addLayout(self.horizontalLayout_2) self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.label_9 = QtWidgets.QLabel(self.widget) self.label_9.setAlignment(QtCore.Qt.AlignCenter) self.label_9.setObjectName("label_9") self.horizontalLayout_3.addWidget(self.label_9) self.label_10 = QtWidgets.QLabel(self.widget) self.label_10.setAlignment(QtCore.Qt.AlignCenter) self.label_10.setObjectName("label_10") self.horizontalLayout_3.addWidget(self.label_10) self.label_11 = QtWidgets.QLabel(self.widget) self.label_11.setAlignment(QtCore.Qt.AlignCenter) self.label_11.setObjectName("label_11") self.horizontalLayout_3.addWidget(self.label_11) self.label_12 = QtWidgets.QLabel(self.widget) self.label_12.setAlignment(QtCore.Qt.AlignCenter) self.label_12.setObjectName("label_12") self.horizontalLayout_3.addWidget(self.label_12) self.verticalLayout.addLayout(self.horizontalLayout_3) self.widget1 = QtWidgets.QWidget(self.centralwidget) self.widget1.setGeometry(QtCore.QRect(220, 570, 321, 151)) self.widget1.setObjectName("widget1") self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.widget1) self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_13 = QtWidgets.QLabel(self.widget1) self.label_13.setAlignment(QtCore.Qt.AlignCenter) self.label_13.setObjectName("label_13") self.horizontalLayout_4.addWidget(self.label_13) self.label_14 = QtWidgets.QLabel(self.widget1) self.label_14.setAlignment(QtCore.Qt.AlignCenter) self.label_14.setObjectName("label_14") self.horizontalLayout_4.addWidget(self.label_14) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 766, 26)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "FPO")) self.label_1.setText(_translate("MainWindow", "1")) self.label_2.setText(_translate("MainWindow", "1")) self.label_3.setText(_translate("MainWindow", "1")) self.label_4.setText(_translate("MainWindow", "1")) self.label_5.setText(_translate("MainWindow", "1")) self.label_6.setText(_translate("MainWindow", "1")) self.label_7.setText(_translate("MainWindow", "1")) self.label_8.setText(_translate("MainWindow", "1")) self.label_9.setText(_translate("MainWindow", "1")) self.label_10.setText(_translate("MainWindow", "1")) self.label_11.setText(_translate("MainWindow", "1")) self.label_12.setText(_translate("MainWindow", "1")) self.label_13.setText(_translate("MainWindow", "1")) self.label_14.setText(_translate("MainWindow", "1"))
项目启动代码如下:
# -*- coding: utf-8 -*- import sys import time import threading from PyQt5.QtGui import QPixmap, QImage from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QGraphicsOpacityEffect from GUI import Ui_MainWindow import cv2 import numpy as np def cv_imread(file_path): cv_img = cv2.imdecode(np.fromfile(file_path, dtype=np.uint8), -1) return cv_img class SnapFinger(QMainWindow, Ui_MainWindow): num = 0 flag_btn_start = True flag_hero_revive = False choose_list = [] def __init__(self): super(SnapFinger, self).__init__() self.setupUi(self) self.setFixedSize(self.width(), self.height()) self.label_all = [self.label_1, self.label_2, self.label_3, self.label_4, self.label_5, self.label_6, self.label_7, self.label_8, self.label_9, self.label_10, self.label_11, self.label_12, self.label_13, self.label_14] self.deal_with_label_all() file_path_1 = 'resources/BlackPanther.jpg' file_path_2 = 'resources/BlackWidow.jpg' file_path_3 = 'resources/CaptainAmerica.jpg' file_path_4 = 'resources/Clint.jpg' file_path_5 = 'resources/DoctorStranger.jpg' file_path_6 = 'resources/Drax.jpg' file_path_7 = 'resources/Groot.jpg' file_path_8 = 'resources/Hulk.jpg' file_path_9 = 'resources/Mantis.jpg' file_path_10 = 'resources/Nebula.jpg' file_path_11 = 'resources/SpiderMan.jpg' file_path_12 = 'resources/Thor.jpg' file_path_13 = 'resources/Vision.jpg' file_path_14 = 'resources/Winter.jpg' self.file_path_label_all = [file_path_1, file_path_2, file_path_3, file_path_4, file_path_5, file_path_6, file_path_7, file_path_8, file_path_9, file_path_10, file_path_11, file_path_12, file_path_13, file_path_14] self.load_image_to_label() btn_img_file_1 = "QPushButton{border-image: url(resources/thanos_1.png)}" btn_img_file_2 = "QPushButton{border-image: url(resources/thanos_2.png)}" btn_img_file_3 = "QPushButton{border-image: url(resources/thanos_3.png)}" btn_img_file_4 = "QPushButton{border-image: url(resources/thanos_4.png)}" self.file_path_btn_all = [btn_img_file_1, btn_img_file_2, btn_img_file_3, btn_img_file_4] self.load_image_to_btn() self.btn_start.clicked.connect(self.slot_btn_start) def deal_with_label_all(self): for i in range(14): self.label_all[i].setScaledContents(True) def deal_with_image_for_cv2(self, image): # 提取图像的尺寸和通道, 用于将opencv下的image转换成Qimage height, width, channel = image.shape bytesPerLine = 3 * width self.qImg = QImage(image.data, width, height, bytesPerLine, QImage.Format_RGB888).rgbSwapped() # 将Qimage显示出来 px = QPixmap() px_1 = px.fromImage(self.qImg) return px_1 def load_image_to_btn(self): self.btn_start.setStyleSheet(self.file_path_btn_all[0]) def load_image_to_label(self): for i in range(14): self.img = cv_imread(self.file_path_label_all[i]) if self.img.size == 1: return px_1 = self.deal_with_image_for_cv2(self.img) self.label_all[i].setPixmap(px_1) def select_image_random(self): z = 0 temp_list = [] while z < 7: tt = np.random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) if tt not in temp_list: temp_list.append(int(tt)) z += 1 else: pass for i in temp_list: self.choose_list.append(self.label_all[i]) def appear_fun(self, cn): n = 0 op = QGraphicsOpacityEffect() for i in range(100): op.setOpacity(n) cn.setGraphicsEffect(op) n += 0.01 time.sleep(0.01) def image_appear(self): self.btn_start.setStyleSheet(self.file_path_btn_all[3]) for cn in self.choose_list: self.appear_fun(cn) time.sleep(0.05) self.choose_list = [] self.btn_start.setStyleSheet(self.file_path_btn_all[0]) self.flag_btn_start = True def disappear_fun(self, cn): n = 1 op = QGraphicsOpacityEffect() for i in range(100): op.setOpacity(n) cn.setGraphicsEffect(op) n -= 0.01 time.sleep(0.01) def image_disappear(self): self.select_image_random() for cn in self.choose_list: self.disappear_fun(cn) time.sleep(0.05) self.btn_start.setStyleSheet(self.file_path_btn_all[0]) self.flag_hero_revive = True def thread_1(self): self.btn_start.setStyleSheet(self.file_path_btn_all[1]) time.sleep(1) self.btn_start.setStyleSheet(self.file_path_btn_all[2]) time.sleep(0.5) t_2 = threading.Thread(target=self.image_disappear) t_2.start() def slot_btn_start(self): if self.flag_btn_start == True: self.flag_btn_start = False t_1 = threading.Thread(target=self.thread_1) t_1.start() elif self.flag_hero_revive == True: self.flag_hero_revive = False t_3 = threading.Thread(target=self.image_appear) t_3.start() else: pass def closeEvent(self, event): reply = QMessageBox.question(self, 'Exit', 'Are you sure to exit"http://xiazai.jb51.net/202005/yuanma/Python_PyQt5_miebaxzh_jb51.rar">http://xiazai.jb51.net/202005/yuanma/Python_PyQt5_miebaxzh_jb51.rar总结
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Python+PyQt5实现灭霸响指功能”评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新动态
2024年11月24日
2024年11月24日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]