B站弹幕宠物练级脚本
B站的弹幕宠物是一种创新的直播互动方式,(B站弹幕宠物练级脚本或者B站自动发弹幕(b站弹幕姬)实现途径都大差不差在直播间用脚本自动发弹幕就可以了),B站的弹幕宠物它允许观众通过发送弹幕指令来控制屏幕上的宠物进行各种动作,从而增加直播的趣味性和互动性。以下是对B站弹幕宠物的详细介绍:
一、基本功能
弹幕控制:观众可以通过发送特定的弹幕指令,如“左”、“右”、“前”、“后”加上数字表示移动距离,来控制宠物的移动。此外,还有如“跳”、“嗨起来”、“坐下”等动作指令,使宠物能够执行相应的动作。
礼物互动:观众赠送特定礼物,如幸运气球或盲盒道具,可以触发宠物的特殊效果。例如,幸运气球可以让宠物飞起来,而盲盒道具则可以随机改变宠物的形态或赋予其特殊能力。
模型切换:观众可以发送指令切换宠物的模型,B站提供了多种免费的宠物模型供选择,如熊猫、小狗、小猫等,同时还有付费模型如孙悟空、火龙等,增加了宠物的多样性。
修仙玩法:观众和主播可以通过发送弹幕指令参与修仙玩法,提高宠物的修炼速度,尝试突破和升级。这种玩法结合了养成和角色扮演的元素,为直播增添了更多的趣味性和挑战性。
B站猫猫养成的详细介绍:
一、猫猫养成的基本玩法
初始选择:用户初次参与猫猫养成时,会从“棉花糖、度假猫、三花”等模型中随机选择一个作为自己的初始猫咪。
互动指令:用户可以通过发送弹幕指令来与猫咪进行互动,如“修炼”、“查询”(显示玩家资料)、“背包”(查看已拥有和可购买的物品)、“购买XXX”(购买物品)、“使用XXX”(使用物品)等。
经验获取与升级:通过喂食(如毛线球)和使用逗猫棒等道具,猫咪可以获得经验并升级。升级后,猫咪可能会解锁新的外观或特效。
二、猫猫养成的特色功能
特效触发:投喂特定数量的礼物(如毛线球、西瓜等)可以触发不同的特效,如猫猫拳、假期躺平卡等。
结婚系统:投喂“喜结良缘”礼物后,猫咪可以进入结婚系统,并与其他猫咪“结婚”并贴贴。
弹幕互动:用户可以通过发送弹幕来参与猫猫养成的互动,如发送“召唤宠物”、“打劫”等指令来与其他玩家互动。
猫猫皮肤:B站会定期更新猫猫的皮肤和特效,用户可以通过购买或参与活动来获得。
前言
今天制作的这一款能在B站能指定直播间、自动发送弹幕的功能的脚本,因为我们B站弹幕宠物直接在直播间里发弹幕就可以被识别到,我们只需要完成弹幕宠物的修炼升级就行,没有必要搞那么多花里胡哨的,只要能稳定的挂机升级就行,所以没做那么多的功能,所以代码很简单。
首先我们去b站找到下面示例代码的直播间,房间号是:
3199583
下面是最简单的实现代码, 可以直接运行使用
# -*-coding: UTF-8
# @Time : 2024/9/18 18:44
# @Author : Cooper
# @FileName: 弹幕宠物脚本4.py
# @Software: PyCharm
# -*-coding: UTF-8
import random
import time
import requests
lis_text2 = ['修仙', '突破', ]
# 弹幕宠物的修炼的专属直播间
roomid='3199583'
# roomid='32288552'
def send():
a = 0
while True:
if a:
send_meg = random.choice(lis_text2)
else:
send_meg = '修仙'
url = 'https://api.live.bilibili.com/msg/send'
data = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1726055988',
'roomid': '{}'.format(roomid),
'csrf': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
'csrf_token': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
}
data2 = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1724769083',
'roomid': '{}'.format(roomid),
'csrf': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
'csrf_token': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
}
headers = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO3516148326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022020211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F618283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2022-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
headers2 = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO2716289372509581; buvid3=0A947BA8-C8B5-9629-FC30-620F495459C292687infoc; b_nut=1717818992; _uuid=77CFE354-6B18-88EC-C5104-EF3C6B7CD32604481infoc; buvid4=EA97A437-6A1E-5D77-7EAA-41216E5EE70204642-024060803-uKTCo5OhsuB8ZPKGZhlC%2BA%3D%3D; CURRENT_FNVAL=4048; fingerprint=1e4715b5de92b6bfac1ad49838d7885a; buvid_fp_plain=undefined; buvid_fp=1e4715b5de92b6bfac1ad49838d7885a; DedeUserID=3546699612031082; DedeUserID__ckMd5=5fdb487ae63b2b9f; rpdid=|(J|~|Jkum|)0J'u~u)~mRRYu; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjUwMTQxODQsImlhdCI6MTcyNDc1NDkyNCwicGx0IjotMX0.uYScHOUqdQ-wgoSzjsDHo1e4TV_d-DvnEW_WFfbv7FA; bili_ticket_expires=1725014124; SESSDATA=beb38df7%2C1740306987%2C6496e%2A82CjDHbd1etLnNbbSDUXzQwd-Ms9X3xygovQyFjekW5zYPIydQ6Hk4aQ9tdQX9WEtdmSUSVkhzNS1qbFJRUmRwLWg2YURCVHZZczNKeTNhQ09JUFctQkN0ZzlBbk1EY0pKazlINzZZamtua3pMaHRMTzMyUlNmM0tKeEpVT013UlVIZHlpWDhPY2VnIIEC; bili_jct=59d7ac13d06cfb1f56af44eebc9a9941; sid=f20hv94y; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755017,1724757169; bp_t_offset_3546699612031082=970557188923719680; b_lsid=59C948D8_1919F135EC8; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
a += 1
response = requests.post(url=url, data=data, headers=headers)
response2 = requests.post(url=url, data=data2, headers=headers2)
print('大号斯蒂芬', response, end='\t')
print('小号幻雪', response2)
time.sleep(200)
send()
运行结果,看到了我的b站的大号小号的各自发送了一条弹幕修仙,这时候我的弹幕宠物可以修炼了。
需要改成自己的账号的地方
'csrf': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
'csrf_token': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
和这里
# 新账号需要改cookie
# 'Cookie': "LIVE_BUVID=AUTO3516048326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022000211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F608283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2002-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'Cookie': "buvid3=0A929476-B840-32B4-3F5C-3C6C0B162D4648875infoc; b_nut=1725698848; _uuid=E43FA16A-72C10-BA32-81010B-6DC10A197CABB51096infoc; buvid4=C8FA3BCA-213C-F996-DFE4-2123F12CD24451628-024090708-CWDZBzdYGHaDiK77MGDu0g%3D%3D; enable_web_push=DISABLE; header_theme_version=CLOSE; home_feed_column=5; browser_resolution=1872-909; LIVE_BUVID=AUTO5917277516958839; CURRENT_FNVAL=4048; rpdid=|(umRYkkJlYu0J'u~k~~lkYR|; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; fingerprint=43a705ca1a3b90fb189ed920a459f118; buvid_fp_plain=undefined; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzI4MDQzMDQsImlhdCI6MTczMjU0NTA0NCwicGx0IjotMX0.w8reVlT_6Z6dwkgTUnlJljxzesDmATxTX699qjqQYkA; bili_ticket_expires=1732804244; SESSDATA=e472f8ff%2C1748097111%2C71c99%2Ab1CjAww1PHawpPhvi3muS4jtC4w0hfohLoINjbvOLvo6rNixMHQ39OYomIuf4AKWD0YZ8SVlZFTV9zbHZyS085UjhrTjVwODFhRzJVeDNmaUFiOEl3bXNnVnBiR2thcWNyT2luSHJma05zTGxYMzgwMW0yOUNFNFBCMDJhdWJYOWpXenprNDFNazBRIIEC; bili_jct=9724432a18291d5b12dac35c809ac7ef; buvid_fp=43a705ca1a3b90fb189ed920a459f118; b_lsid=AF7331010E_193679E5A40; match_float_version=ENABLE; sid=mfsfdabt; bp_t_offset_17648823=1004043223569530880; PVID=2; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1731407078,1732610479; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1732610479; HMACCOUNT=B1D0AE8C1B766655",
获取csrf_token
随便点开一个直播间(先登录),后点F12.
在直播间发送666
版本一
# -*-coding: UTF-8
# @Time : 2024/9/18 18:44
# @Author : Cooper
# @FileName: 弹幕宠物脚本4.py
# @Software: PyCharm
# -*-coding: UTF-8
import random
import time
from tkinter import *
import requests
lis_text2 = ['修仙', '突破', ]
def send():
a = 0
while True:
if a:
send_meg = random.choice(lis_text2)
else:
send_meg = '修仙'
roomid = entry.get()
url = 'https://api.live.bilibili.com/msg/send'
data = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1726055988',
'roomid': '{}'.format(roomid),
'csrf': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
'csrf_token': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
}
data2 = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1724769083',
'roomid': '{}'.format(roomid),
'csrf': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
'csrf_token': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
}
headers = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO3516148326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022020211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F618283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2022-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
headers2 = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO2716289372509581; buvid3=0A947BA8-C8B5-9629-FC30-620F495459C292687infoc; b_nut=1717818992; _uuid=77CFE354-6B18-88EC-C5104-EF3C6B7CD32604481infoc; buvid4=EA97A437-6A1E-5D77-7EAA-41216E5EE70204642-024060803-uKTCo5OhsuB8ZPKGZhlC%2BA%3D%3D; CURRENT_FNVAL=4048; fingerprint=1e4715b5de92b6bfac1ad49838d7885a; buvid_fp_plain=undefined; buvid_fp=1e4715b5de92b6bfac1ad49838d7885a; DedeUserID=3546699612031082; DedeUserID__ckMd5=5fdb487ae63b2b9f; rpdid=|(J|~|Jkum|)0J'u~u)~mRRYu; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjUwMTQxODQsImlhdCI6MTcyNDc1NDkyNCwicGx0IjotMX0.uYScHOUqdQ-wgoSzjsDHo1e4TV_d-DvnEW_WFfbv7FA; bili_ticket_expires=1725014124; SESSDATA=beb38df7%2C1740306987%2C6496e%2A82CjDHbd1etLnNbbSDUXzQwd-Ms9X3xygovQyFjekW5zYPIydQ6Hk4aQ9tdQX9WEtdmSUSVkhzNS1qbFJRUmRwLWg2YURCVHZZczNKeTNhQ09JUFctQkN0ZzlBbk1EY0pKazlINzZZamtua3pMaHRMTzMyUlNmM0tKeEpVT013UlVIZHlpWDhPY2VnIIEC; bili_jct=59d7ac13d06cfb1f56af44eebc9a9941; sid=f20hv94y; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755017,1724757169; bp_t_offset_3546699612031082=970557188923719680; b_lsid=59C948D8_1919F135EC8; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
a += 1
response = requests.post(url=url, data=data, headers=headers)
response2 = requests.post(url=url, data=data2, headers=headers2)
print('大号斯蒂芬', response, end='\t')
print('小号幻雪', response2)
text.insert(END, '第{}条弹幕发送成功'.format(a))
# 文本框滚动
text.see(END)
# 更新
text.update()
text.insert(END, '发送内容:{}'.format(send_meg))
time.sleep(200)
root = Tk()
root.title('B站自动发送弹幕')
root.geometry('560x450+400+200')
label = Label(root, text='请输入房间ID:', font=('华文行楷', 22))
label.grid()
entry = Entry(root, font=('隶书', 20), width=26)
entry.grid(row=0, column=1)
text = Listbox(root, font=('隶书', 16), width=50, heigh=15)
text.grid(row=2, columnspan=2)
button1 = Button(root, text='开始发送', font=('隶书', 15), command=send)
button1.grid(row=3, column=0)
button2 = Button(root, text='退出程序', font=('隶书', 15), command=root.quit)
button2.grid(row=3, column=1)
root.mainloop()
运行结果
版本二
# @Python : 3.13
# @FileName : 弹幕宠物qt版2.2.py
# @time : 2004/11/10 10:26
# @Author : Cooper
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget
import random
import requests
from PyQt5.QtCore import QThread, pyqtSignal
import time
import img_rc
from PyQt5.QtWidgets import QDesktopWidget
import sys
from requests.exceptions import ReadTimeout, HTTPError, RequestException
lis_text2 = ['修仙', '突破', '打坐', '修炼', '签到']
a = 0
class QMainWindow(QtWidgets.QMainWindow):
"""对QMainWindow类重写,实现一些功能"""
def closeEvent(self, event):
"""重写closeEvent方法,实现dialog窗体关闭时执行一些代码
:param event: close()触发的事件
:return: None
"""
print('这里2')
reply = QtWidgets.QMessageBox.question(self,
'本程序',
"是否要退出程序?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
event.accept()
else:
event.ignore()
class WorkerThread(QThread):
# 定义一个信号,用于通知主线程任务完成
middle_signal = pyqtSignal(str)
finished_signal = pyqtSignal()
def run(self):
# 耗时任务要放在线程中
try:
while True:
global a
print('ok')
# 定义一个信号发送给主线程
self.middle_signal.emit(f"Thread: {a + 1}")
time.sleep(500)
print(f"Working... {a}")
# 任务完成后发射信号
except Exception as e:
print(e)
self.finished_signal.emit()
class Ui_MainWindow(QWidget):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(555, 350)
font = QtGui.QFont()
font.setFamily("方正姚体简体")
MainWindow.setFont(font)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/jpg/Apple.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setStyleSheet("\n"
"#centralwidget{border-image: url(:/jpg/ironman.jpg);}")
self.centralwidget.setObjectName("centralwidget")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(0, 75, 550, 230))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.textBrowser.setPalette(palette)
self.textBrowser.setAutoFillBackground(True)
self.textBrowser.setObjectName("textBrowser")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 550, 90))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正北魏楷书简体")
font.setPointSize(20)
self.label.setFont(font)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.lineEdit.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("SimSun")
font.setPointSize(15)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(45, 310, 90, 30))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/jpg/登录 .png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon1)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(370, 310, 90, 30))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/jpg/退出.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon2)
self.pushButton_2.setObjectName("pushButton_2")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(200, 315, 100, 20))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_2.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正卡通简体")
font.setPointSize(15)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
# 创建QGraphicsOpacityEffect对象
op = QtWidgets.QGraphicsOpacityEffect()
op.setOpacity(1) # 0.5是透明度
self.textBrowser.setGraphicsEffect(op)
self.textBrowser.setAutoFillBackground(True)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
self.pushButton_2.clicked.connect(MainWindow.close) # type: ignore
# self.pushButton.clicked.connect(self.label_2.clear) # type: ignore
self.pushButton.clicked.connect(self.start_thread) # type: ignore
self.pushButton.clicked.connect(self.label_2.clear) # type: ignore
self.lineEdit.editingFinished.connect(self.label_2.clear) # type: ignore
self.lineEdit.editingFinished.connect(self.start_thread) # type: ignore
# 创建线程实例
self.thread = WorkerThread()
# 连接信号到槽函数
self.thread.middle_signal.connect(self.on_middle)
self.thread.finished_signal.connect(self.on_finished)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "弹幕宠物修炼"))
self.label.setText(_translate("MainWindow", "请输入房间号:"))
self.pushButton.setText(_translate("MainWindow", "开始发送"))
self.pushButton_2.setText(_translate("MainWindow", "退出程序"))
self.label_2.setText(_translate("MainWindow", "等待运行 !"))
self.lineEdit.setText(_translate("MainWindow", "1769474447"))
self.textBrowser.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'黑体\'; font-size:12pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">弹幕列表:</p></body></html>"))
def slot(self):
print('正在运行')
self.updateUi()
time.sleep(10)
self.textBrowser.clear()
def start_thread(self):
# 启动线程
self.thread.start()
def on_middle(self, message):
# 线程中间的处理
print("Thread middle")
self.send()
self.label.setText(message)
def on_finished(self):
# 线程完成后的处理
print("Thread finished!")
self.label.setText("Thread finished!")
def updateUi(self, message):
try:
text = ' '
message += text
self.textBrowser.append("<pre><br> %s </br></pre>" % message) # 显示内容支撑html格式语法
except:
self.textBrowser.append("<font color=red>%s is invalid!</font>" % message)
def send(self):
global a
# while True:
if a:
send_meg = random.choice(lis_text2)
else:
send_meg = '修仙'
roomid = self.lineEdit.text()
url = 'https://api.live.bilibili.com/msg/send'
data = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1726055988',
'roomid': '{}'.format(roomid),
'csrf': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
'csrf_token': '4cb23f0382a5c1d8bda997b24f5be710', # 新账号需要改这里
}
data2 = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1724769083',
'roomid': '{}'.format(roomid),
'csrf': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
'csrf_token': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
}
headers = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO3516048326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022000211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F608283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2002-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'Cookie': "buvid3=0A929476-B840-32B4-3F5C-3C6C0B162D4648875infoc; b_nut=1725698848; _uuid=E43FA16A-72C10-BA32-81010B-6DC10A197CABB51096infoc; buvid4=C8FA3BCA-213C-F996-DFE4-2123F12CD24451628-024090708-CWDZBzdYGHaDiK77MGDu0g%3D%3D; enable_web_push=DISABLE; header_theme_version=CLOSE; home_feed_column=5; browser_resolution=1872-909; LIVE_BUVID=AUTO5917277516958839; CURRENT_FNVAL=4048; rpdid=|(umRYkkJlYu0J'u~k~~lkYR|; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzE2NDIzNjIsImlhdCI6MTczMTM4MzEwMiwicGx0IjotMX0.UN3AO6D2TO5c8wAJSNxu4I8GWImyGjPyj6cnbJq3u4E;",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
headers2 = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO2716289372509581; buvid3=0A947BA8-C8B5-9629-FC30-620F495459C292687infoc; b_nut=1717818992; _uuid=77CFE354-6B18-88EC-C5104-EF3C6B7CD32604481infoc; buvid4=EA97A437-6A1E-5D77-7EAA-41216E5EE70204642-024060803-uKTCo5OhsuB8ZPKGZhlC%2BA%3D%3D; CURRENT_FNVAL=4048; fingerprint=1e4715b5de92b6bfac1ad49838d7885a; buvid_fp_plain=undefined; buvid_fp=1e4715b5de92b6bfac1ad49838d7885a; DedeUserID=3546699602031082; DedeUserID__ckMd5=5fdb487ae63b2b9f; rpdid=|(J|~|Jkum|)0J'u~u)~mRRYu; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjUwMTQxODQsImlhdCI6MTcyNDc1NDkyNCwicGx0IjotMX0.uYScHOUqdQ-wgoSzjsDHo1e4TV_d-DvnEW_WFfbv7FA; bili_ticket_expires=1725014124; SESSDATA=beb38df7%2C1740306987%2C6496e%2A82CjDHbd1etLnNbbSDUXzQwd-Ms9X3xygovQyFjekW5zYPIydQ6Hk4aQ9tdQX9WEtdmSUSVkhzNS1qbFJRUmRwLWg2YURCVHZZczNKeTNhQ09JUFctQkN0ZzlBbk1EY0pKazlINzZZamtua3pMaHRMTzMyUlNmM0tKeEpVT013UlVIZHlpWDhPY2VnIIEC; bili_jct=59d7ac13d06cfb1f56af44eebc9a9941; sid=f20hv94y; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755017,1724757169; bp_t_offset_3546699602031082=970557188923719680; b_lsid=59C948D8_1919F135EC8; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
a += 1
print(roomid)
try:
response = requests.post(url=url, data=data, headers=headers, timeout=10)
response2 = requests.post(url=url, data=data2, headers=headers2, timeout=10)
print('大号斯蒂芬', response, end='\t')
print('小号幻雪', response2)
except HTTPError:
print('httperror')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'httperror'))
except RequestException:
print('reqerror')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'reqerror'))
except ReadTimeout:
print('time out')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'time out'))
except Exception as e:
print(e)
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(str(e)))
else:
self.updateUi('第{}条弹幕发送成功, '.format(a) + '发送内容:{}, '.format(send_meg))
# 必须添加第二个类来继承添加窗口属性不然报错AttributeError: 'Ui_MainWindow' object has no attribute 'geometry'
class Agent(Ui_MainWindow, QtWidgets.QWidget, ):
def center(self):
# 获得屏幕坐标系
screen = QDesktopWidget().screenGeometry()
# 获得窗口坐标系
size = self.geometry()
# 获得窗口相关坐标
newLeft = (screen.width() - size.width()) // 2
newTop = (screen.height() - size.height()) // 2
# 移动窗口使其居中
self.move(newLeft, newTop)
class Ui_MainWindow(Agent):
pass
def show_MainWindow():
app = QtWidgets.QApplication(sys.argv) # 实例化QApplication类,作为GUI主程序入口
MainWindow = QMainWindow() # 注意修改为了自己重写的QMainWindow类
MainWindow.setStyleSheet("#MainWindow{background-color:#C0E6FF}") # 设置背景颜色
ui = Ui_MainWindow() # 实例化ui类
ui.setupUi(MainWindow) # 设置窗口UI
ui.center() # 调用方法使窗口居中
MainWindow.show() # 显示窗口
sys.exit(app.exec_()) # 当窗口创建完成时,需要结束主循环过程
if __name__ == "__main__":
show_MainWindow()
运行效果
下面是2025年超级无敌最终强化版本
# @Python : 3.13
# @FileName : 弹幕宠物修炼或猫猫养成练级脚本.py
# @time : 2024/11/26 17:27
# @Author : Cooper
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget
import random
import requests
from PyQt5.QtCore import QThread, pyqtSignal
import time
import img_rc
from PyQt5.QtWidgets import QDesktopWidget
import sys
from requests.exceptions import ReadTimeout, HTTPError, RequestException
lis_text = ['喵', '贴贴', '猫猫冲撞', '修炼', 'boom', '签到']
lis_text2 = ['修仙', '突破', '打坐', '修炼', '签到']
a = 0 # 发送弹幕的次数
delay = 600 # 弹幕发送时间间隔
do_work = True # 弹幕是否发送标志位
do_work2 = True # 弹幕是否是第一次发送
do_work3 = True # 弹幕宠物修炼还是猫猫养成练级标志位
class QMainWindow(QtWidgets.QMainWindow):
"""对QMainWindow类重写,实现一些功能"""
def closeEvent(self, event):
"""重写closeEvent方法,实现dialog窗体关闭时执行一些代码
:param event: close()触发的事件
:return: None
"""
print('这里2')
reply = QtWidgets.QMessageBox.question(self,
'本程序',
"是否要退出程序?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
global do_work
do_work = False # 弹幕是否发送标志位
event.accept()
else:
event.ignore()
class WorkerThread(QThread):
# 定义一个信号,用于通知主线程任务完成
middle_signal = pyqtSignal(str)
finished_signal = pyqtSignal()
def run(self):
# 耗时任务要放在线程中
try:
while do_work:
global a
# 定义一个信号发送给主线程
self.middle_signal.emit(f"Thread: {a + 1}")
print(f"Working... {a}")
for i in range(delay):
print(i)
if not do_work:
break
time.sleep(1)
# 任务完成后发射信号
self.finished_signal.emit()
except Exception as e:
print(e)
self.finished_signal.emit()
class Ui_MainWindow(QWidget):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(555, 380)
font = QtGui.QFont()
font.setFamily("方正姚体简体")
MainWindow.setFont(font)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/jpg/Apple.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setStyleSheet("\n"
"#centralwidget{border-image: url(:/jpg/ironman.jpg);}")
self.centralwidget.setObjectName("centralwidget")
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(0, 75, 550, 230))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(240, 60, 200))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 130))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.textBrowser.setPalette(palette)
self.textBrowser.setAutoFillBackground(True)
self.textBrowser.setObjectName("textBrowser")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 550, 50))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正北魏楷书简体")
font.setPointSize(20)
self.label.setFont(font)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.lineEdit.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("SimSun")
font.setPointSize(15)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setValidator(QtGui.QIntValidator())
# _____________________
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(0, 40, 200, 30))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_2.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正北魏楷书简体")
font.setPointSize(16)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(202, 42, 348, 30))
self.lineEdit_2.setObjectName("lineEdit")
font = QtGui.QFont()
font.setFamily("SimSun")
font.setPointSize(15)
self.lineEdit_2.setFont(font)
self.lineEdit_2.setObjectName("lineEdit")
# 正则表达式匹配0-890的数
self.lineEdit_2.setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("^(890|[1-7][0-9]{0,2}|[1-9][0-9]?|0|8[0-8][0-9])$")))
# _____________________
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 310, 90, 30))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/jpg/登录 .png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon1)
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(300, 310, 90, 30))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/jpg/退出.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon2)
self.pushButton_2.setObjectName("pushButton_2")
#
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(170, 310, 90, 30))
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(":/jpg/clear.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon3)
self.pushButton_3.setObjectName("pushButton_3")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(410, 328, 150, 40))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_3.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正卡通简体")
font.setPointSize(20)
self.label_3.setFont(font)
self.label_3.setObjectName("label_2")
# 创建QGraphicsOpacityEffect对象
op = QtWidgets.QGraphicsOpacityEffect()
op.setOpacity(1) # 0.5是透明度
self.textBrowser.setGraphicsEffect(op)
self.textBrowser.setAutoFillBackground(True)
self.radioButton = QtWidgets.QRadioButton(MainWindow)
self.radioButton.setGeometry(QtCore.QRect(40, 350, 120, 30))
self.radioButton.setPalette(palette)
self.radioButton.setChecked(True)
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtWidgets.QRadioButton(MainWindow)
self.radioButton_2.setGeometry(QtCore.QRect(300, 350, 120, 30))
self.radioButton_2.setPalette(palette)
self.radioButton_2.setObjectName("radioButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
# 按钮绑定任务
self.pushButton_2.clicked.connect(self.slot4) # type: ignore
# self.pushButton.clicked.connect(self.label_2.clear) # type: ignore
self.pushButton.clicked.connect(self.start_thread) # type: ignore
# self.pushButton.clicked.connect(self.slot2) # type: ignore
self.pushButton_3.clicked.connect(self.slot) # type: ignore
# self.lineEdit.editingFinished.connect(self.label_3.clear) # type: ignore
self.lineEdit.editingFinished.connect(self.slot2) # type: ignore
self.lineEdit_2.editingFinished.connect(self.slot3) # type: ignore
self.lineEdit_2.textChanged.connect(self.slot3) # type: ignore
self.radioButton_2.toggled.connect(self.slot5) # type: ignore
# 创建线程实例
self.thread = WorkerThread()
# 连接信号到槽函数
self.thread.middle_signal.connect(self.on_middle)
self.thread.finished_signal.connect(self.on_finished)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "弹幕宠物修炼或猫猫养成练级脚本"))
self.label.setText(_translate("MainWindow", "请输入房间号:"))
self.pushButton.setText(_translate("MainWindow", "开始发送"))
self.pushButton_2.setText(_translate("MainWindow", "停止发送"))
self.pushButton_3.setText(_translate("MainWindow", "清空列表"))
self.label_2.setText(_translate("MainWindow", "弹幕发送时间间隔:"))
self.label_3.setText(_translate("MainWindow", "等待运行 !"))
self.pushButton.setShortcut('ctrl+d') # 设置登录快捷键(设置一些功能的参数推荐放在当前的retranslateUi下)
self.pushButton_2.setShortcut('Ctrl+q') # 设置退出快捷键
self.pushButton_3.setShortcut('Ctrl+s') # 设置退出快捷键
self.lineEdit.setText(_translate("MainWindow", "1769474447"))
self.lineEdit_2.setText(_translate("MainWindow", str(delay)))
self.radioButton.setText(_translate("Form", "弹幕宠物"))
self.radioButton_2.setText(_translate("Form", "猫猫养成"))
self.textBrowser.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'黑体\'; font-size:12pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">弹幕列表:</p></body></html>"))
def slot(self, MainWindow):
print('正在运行')
# self.textBrowser.clear()
self.textBrowser.setHtml(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'黑体\'; font-size:12pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">弹幕列表:</p></body></html>")
def slot2(self):
print('房间号:', self.lineEdit.text())
def slot3(self): # 更新弹幕发送的延时时间
print(self.lineEdit_2.text())
global delay
delay = int(self.lineEdit_2.text())
def slot4(self): # 停止发送
global do_work, do_work2
do_work = False
do_work2 = False
# 设置 QLabel 的样式表以改变字体颜色
self.label_3.setStyleSheet("color: red;")
self.label_3.setText('等待运行!')
def slot5(self): # 停止发送
print('slot5')
global do_work3
do_work3 = not do_work3
if do_work3:
self.lineEdit.setText('1769474447')
else:
self.lineEdit.setText('32534986')
print(self.lineEdit.text())
def start_thread(self):
global do_work
do_work = True
# 启动线程
self.label_3.setStyleSheet("color: yellow;")
self.label_3.setText('正在运行!')
self.thread.start()
def on_middle(self, message):
# 线程中间的处理
print("Thread middle")
self.send()
self.label.setText(message)
def on_finished(self):
# 线程完成后的处理
print("Thread finished!")
self.label.setText("Thread finished!")
def updateUi(self, message):
try:
text = ' '
message += text
self.textBrowser.append("<pre><br> %s </br></pre>" % message) # 显示内容支撑html格式语法
except:
self.textBrowser.append("<font color=red>%s is invalid!</font>" % message)
def send(self):
global a, do_work2
# print('do_work2:', do_work2)
if (not a) | (not do_work2):
# print('-'*100)
if do_work3:
send_meg = '修仙'
else:
send_meg = '喵'
do_work2 = True
else:
if do_work3:
send_meg = random.choice(lis_text2)
else:
send_meg = random.choice(lis_text)
roomid = self.lineEdit.text()
url = 'https://api.live.bilibili.com/msg/send'
data = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1726055988',
'roomid': '{}'.format(roomid),
'csrf': '9724432a18291d5b12dac35c809ac7ef', # 新账号需要改这里
'csrf_token': '9724432a18291d5b12dac35c809ac7ef', # 新账号需要改这里
}
data2 = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'fontsize': '50',
'rnd': '1724769083',
'roomid': '{}'.format(roomid),
'csrf': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
'csrf_token': '59d7ac13d06cfb1f56af44eebc9a9941', # 新账号需要改这里
}
headers = {
# 新账号需要改cookie
# 'Cookie': "LIVE_BUVID=AUTO3516048326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022000211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F608283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2002-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'Cookie': "buvid3=0A929476-B840-32B4-3F5C-3C6C0B162D4648875infoc; b_nut=1725698848; _uuid=E43FA16A-72C10-BA32-81010B-6DC10A197CABB51096infoc; buvid4=C8FA3BCA-213C-F996-DFE4-2123F12CD24451628-024090708-CWDZBzdYGHaDiK77MGDu0g%3D%3D; enable_web_push=DISABLE; header_theme_version=CLOSE; home_feed_column=5; browser_resolution=1872-909; LIVE_BUVID=AUTO5917277516958839; CURRENT_FNVAL=4048; rpdid=|(umRYkkJlYu0J'u~k~~lkYR|; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; fingerprint=43a705ca1a3b90fb189ed920a459f118; buvid_fp_plain=undefined; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzI4MDQzMDQsImlhdCI6MTczMjU0NTA0NCwicGx0IjotMX0.w8reVlT_6Z6dwkgTUnlJljxzesDmATxTX699qjqQYkA; bili_ticket_expires=1732804244; SESSDATA=e472f8ff%2C1748097111%2C71c99%2Ab1CjAww1PHawpPhvi3muS4jtC4w0hfohLoINjbvOLvo6rNixMHQ39OYomIuf4AKWD0YZ8SVlZFTV9zbHZyS085UjhrTjVwODFhRzJVeDNmaUFiOEl3bXNnVnBiR2thcWNyT2luSHJma05zTGxYMzgwMW0yOUNFNFBCMDJhdWJYOWpXenprNDFNazBRIIEC; bili_jct=9724432a18291d5b12dac35c809ac7ef; buvid_fp=43a705ca1a3b90fb189ed920a459f118; b_lsid=AF7331010E_193679E5A40; match_float_version=ENABLE; sid=mfsfdabt; bp_t_offset_17648823=1004043223569530880; PVID=2; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1731407078,1732610479; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1732610479; HMACCOUNT=B1D0AE8C1B766655",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
headers2 = {
# 新账号需要改cookie
'Cookie': "LIVE_BUVID=AUTO2716289372509581; buvid3=0A947BA8-C8B5-9629-FC30-620F495459C292687infoc; b_nut=1717818992; _uuid=77CFE354-6B18-88EC-C5104-EF3C6B7CD32604481infoc; buvid4=EA97A437-6A1E-5D77-7EAA-41216E5EE70204642-024060803-uKTCo5OhsuB8ZPKGZhlC%2BA%3D%3D; CURRENT_FNVAL=4048; fingerprint=1e4715b5de92b6bfac1ad49838d7885a; buvid_fp_plain=undefined; buvid_fp=1e4715b5de92b6bfac1ad49838d7885a; DedeUserID=3546699602031082; DedeUserID__ckMd5=5fdb487ae63b2b9f; rpdid=|(J|~|Jkum|)0J'u~u)~mRRYu; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjUwMTQxODQsImlhdCI6MTcyNDc1NDkyNCwicGx0IjotMX0.uYScHOUqdQ-wgoSzjsDHo1e4TV_d-DvnEW_WFfbv7FA; bili_ticket_expires=1725014124; SESSDATA=beb38df7%2C1740306987%2C6496e%2A82CjDHbd1etLnNbbSDUXzQwd-Ms9X3xygovQyFjekW5zYPIydQ6Hk4aQ9tdQX9WEtdmSUSVkhzNS1qbFJRUmRwLWg2YURCVHZZczNKeTNhQ09JUFctQkN0ZzlBbk1EY0pKazlINzZZamtua3pMaHRMTzMyUlNmM0tKeEpVT013UlVIZHlpWDhPY2VnIIEC; bili_jct=59d7ac13d06cfb1f56af44eebc9a9941; sid=f20hv94y; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755017,1724757169; bp_t_offset_3546699602031082=970557188923719680; b_lsid=59C948D8_1919F135EC8; PVID=2",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
a += 1
print(roomid)
try:
response = requests.post(url=url, data=data, headers=headers, timeout=10)
response2 = requests.post(url=url, data=data2, headers=headers2, timeout=10)
print('大号斯蒂芬', response, end='\t')
print('小号幻雪', response2)
except HTTPError:
print('httperror')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'httperror'))
except RequestException:
print('reqerror')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'reqerror'))
except ReadTimeout:
print('time out')
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(
'time out'))
except Exception as e:
print(e)
self.updateUi(
'第{}条弹幕发送失败, '.format(a) + '发送内容:{}, '.format(send_meg) + '错误原因:{}'.format(str(e)))
else:
self.updateUi('第{}条弹幕发送成功, '.format(a) + '发送内容:{}。 '.format(send_meg))
# 必须添加第二个类来继承添加窗口属性不然报错AttributeError: 'Ui_MainWindow' object has no attribute 'geometry'
class Agent(Ui_MainWindow, QtWidgets.QWidget):
def center(self):
# 获得屏幕坐标系
screen = QDesktopWidget().screenGeometry()
# 获得窗口坐标系
size = self.geometry()
# 获得窗口相关坐标
newLeft = (screen.width() - size.width()) // 2
newTop = (screen.height() - size.height()) // 2
# 移动窗口使其居中
self.move(newLeft, newTop)
class Ui_MainWindow(Agent):
pass
def show_MainWindow():
app = QtWidgets.QApplication(sys.argv) # 实例化QApplication类,作为GUI主程序入口
MainWindow = QMainWindow() # 注意修改为了自己重写的QMainWindow类
MainWindow.setStyleSheet("#MainWindow{background-color:#C0E6FF}") # 设置背景颜色
ui = Ui_MainWindow() # 实例化ui类
ui.setupUi(MainWindow) # 设置窗口UI
ui.center() # 调用方法使窗口居中
MainWindow.show() # 显示窗口
sys.exit(app.exec_()) # 当窗口创建完成时,需要结束主循环过程
if __name__ == "__main__":
show_MainWindow()
最终的二合一的版本(B站弹幕宠物练级脚本和B站猫猫养成练级脚本)
# -*- coding: utf-8 -*-
# @Python : 3.9
# @FileName : 弹幕宠物或猫猫养成练级脚本2.3.2.py
# @time : 2024/12/24 15:48
# @Author : Cooper
# from Lib.AnimationShadowEffect import AnimationShadowEffect # @UnresolvedImport
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox, QWidget, QDesktopWidget, QInputDialog
from PyQt5.QtCore import Qt, QDateTime, QThread, pyqtSignal, QPropertyAnimation, QPoint
import random
import requests
import img_rc
import sys
from requests.exceptions import ReadTimeout, HTTPError, RequestException
from Lib.AnimationShadowEffect import AnimationShadowEffect
lis_text = ['喵', '喵', '喵', '喵', '喵', '贴贴', '喵', '修炼', 'boom', '签到']
lis_text2 = ['修仙', '突破', '打坐', '修炼', '签到']
color_list = ['red', 'green', 'blue', 'yellow', 'white', 'black', 'gray', 'orange', 'purple', 'maroon']
a = 0 # 发送弹幕的次数
delay = 600 # 弹幕发送时间间隔
percentage = 0 # 百分比记录
do_work = True # 弹幕是否发送标志位
do_work2 = True # 弹幕是否是第一次发送
class QMainWindow(QtWidgets.QMainWindow):
"""对QMainWindow类重写,实现一些功能"""
def closeEvent(self, event):
"""重写closeEvent方法,实现dialog窗体关闭时执行一些代码
:param event: close()触发的事件
:return: None
"""
print('这里2')
reply = QtWidgets.QMessageBox.question(self,
'本程序',
"是否要退出程序?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
global do_work
do_work = False # 弹幕是否发送标志位
event.accept()
else:
event.ignore()
class WorkerThread(QThread):
# 定义一个信号,用于通知主线程任务完成
middle_signal = pyqtSignal(str)
middle_signal2 = pyqtSignal(int)
finished_signal = pyqtSignal()
def run(self):
global percentage
# 耗时任务要放在线程中
try:
while do_work:
global a
# 定义一个信号发送给主线程
self.middle_signal.emit(f"Thread: {a + 1}")
print(f"Working... {a}")
for i in range(delay):
print(i)
if QThread.currentThread().isInterruptionRequested():
# if not do_work:
percentage = 0
self.middle_signal2.emit(percentage)
print("退出")
break
QThread.sleep(1)
# time.sleep(1)
if percentage < int(i / (delay / 100)):
percentage = int(i / (delay / 100))
self.middle_signal2.emit(percentage)
# 任务完成后发射信号
self.finished_signal.emit()
percentage = 0
except Exception as e:
print(e)
self.finished_signal.emit()
class Ui_MainWindow(QWidget):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1029, 690)
font = QtGui.QFont()
font.setFamily("Consolas")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
MainWindow.setFont(font)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/jpg/Apple.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
MainWindow.setStyleSheet("QMainWindow {background-image:url(:/jpg/preview.jpg);}\n"
"#centralwidget{background-image: url(:/jpg/preview.jpg);}\n"
"*{\n"
" font: 15pt \"Consolas\",\"楷体\" red; \n"
"}\n"
"QPushButton{\n"
" border: 2px solid 1 rgb(85, 255, 255); \n"
" border-radius: 25px; /* 设置圆角半径 */\n"
" color: black;\n"
" padding: 10px 10px;\n"
" text-align: center;\n"
" text-decoration: none;\n"
" display: inline-block; \n"
" font: 15pt \"方正启体简体\"; \n"
" cursor: pointer;\n"
" width: 30px; /* 设置宽度 */\n"
" height: 28px; /* 设置高度 */\n"
" background-color: rgba(97, 255, 94,0.5);\n"
" border-style:solid;\n"
"}\n"
"QLabel{ \n"
" font: 15pt \"方正启体简体\";\n"
"}\n"
" QPushButton:focus {\n"
" border: 2px solid blue; /* 聚焦时的边框颜色 */\n"
" }\n"
" \n"
" QPushButton:hover {/* 鼠标在他上面时候的颜色 */\n"
" background-color: rgb(255, 0, 0)\n"
" }\n"
" \n"
" QPushButton:pressed {\n"
" background-color: #ff3cfc;\n"
" }\n"
" QPushButton:disabled {\n"
" background-color: rgba(97, 255, 94,0.0);\n"
" border: 0px solid 1 rgba(85, 255, 255,0.0);\n"
" color: rgba(85, 255, 255,0.0);\n"
" }\n"
"\n"
"QLineEdit {\n"
" border: 3px solid #8f8f91;\n"
" border-radius:32px; /* 设置圆角半径 */\n"
" padding: 5px;\n"
" background-color: rgba(0, 0, 0, 0);\n"
" color: red; \n"
" font: 16pt \"楷体\";\n"
" }\n"
" \n"
" QLineEdit:focus {\n"
" border-color: #4CAF50; /* 聚焦时边框颜色 */\n"
" outline: none; /* 移除默认的聚焦边框 */\n"
" }\n"
" \n"
" QLineEdit:disabled {\n"
" background-color: #e0e0e0; /* 禁用时背景颜色 */\n"
" color: #808080; /* 禁用时文本颜色 */\n"
" }\n"
"QSpinBox {\n"
" background-color: rgba(231, 255, 207,0.0);\n"
"\n"
" border: 1px solid rgb(231, 255, 207); /* 移除边框,如果你想要一个透明的边框效果,可以设置为1px solid transparent */\n"
" padding: 2px; /* 移除内边距,以确保按钮和编辑框紧贴在一起 */\n"
" /* 注意:QSpinBox的边框和内边距可能会影响透明度的表现,因此这里设置为0 */\n"
"font: 15pt \"方正启体简体\";\n"
"}\n"
"\n"
"/* 进度条整体容器样式 */\n"
"QProgressBar {\n"
" /* 边框:2像素宽、实线、灰色 */\n"
" border: 2px solid grey;\n"
" /* 边框圆角半径10像素(胶囊状效果) */\n"
" border-radius: 5px;\n"
" /* 文本居中显示(适用于显示百分比的情况) */\n"
" text-align: center;\n"
" /* 背景颜色:浅灰色 (#E0E0E0) */\n"
" /*background: #E0E0E0;*/\n"
" background-color: rgba(97, 255, 94,0.0);\n"
"}\n"
"\n"
"/* 进度条填充部分样式 */\n"
"QProgressBar::chunk \n"
"{\n"
" /* 填充色:亮绿色 (#76EE00/CornflowerBlue的替代色) */\n"
" background-color: #76EE00;\n"
" /* 每个进度块的基准宽度(影响块状效果间隔) */\n"
" width: 5px; \n"
" \n"
" \n"
" margin: 0.5px; /* 进度块之间的间隔*/\n"
" border-radius: 5px; /* 与容器圆角配合避免溢出*/\n"
" \n"
"}")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setStyleSheet("")
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_3.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正启体简体")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.label_3.setFont(font)
self.label_3.setAlignment(QtCore.Qt.AlignCenter)
self.label_3.setObjectName("label_3")
self.gridLayout_2.addWidget(self.label_3, 1, 0, 1, 2)
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setEnabled(True)
font = QtGui.QFont()
font.setFamily("楷体")
font.setPointSize(16)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.lineEdit_2.setFont(font)
self.lineEdit_2.setStyleSheet("\n"
"QLineEdit {\n"
" border: 3px solid #8f8f91;\n"
" border-radius:32px; /* 设置圆角半径 */\n"
" padding: 5px;\n"
" background-color: rgba(0, 0, 0, 0);\n"
" color:rgb(16, 255, 228); \n"
" font: 16pt \"楷体\";\n"
" }\n"
" \n"
" QLineEdit:focus {\n"
" border-color: #4CAF50; /* 聚焦时边框颜色 */\n"
" outline: none; /* 移除默认的聚焦边框 */\n"
" }\n"
" \n"
" QLineEdit:disabled {\n"
" background-color: #e0e0e0; /* 禁用时背景颜色 */\n"
" color: #808080; /* 禁用时文本颜色 */\n"
" }")
self.lineEdit_2.setObjectName("lineEdit_2")
self.gridLayout_2.addWidget(self.lineEdit_2, 1, 2, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
self.lineEdit.setSizePolicy(sizePolicy)
self.lineEdit.setMaximumSize(QtCore.QSize(16777215, 16777215))
font = QtGui.QFont()
font.setFamily("楷体")
font.setPointSize(16)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.lineEdit.setFont(font)
self.lineEdit.setStyleSheet("\n"
"QLineEdit {\n"
" border: 3px solid #8f8f91;\n"
" border-radius: 3px; /* 设置圆角半径 */\n"
" padding: 5px;\n"
" background-color: rgba(0, 0, 0, 0); \n"
" color: rgb(12, 255, 255); \n"
" font: 16pt \"楷体\";\n"
" \n"
" }\n"
" \n"
" QLineEdit:focus {\n"
" border-color: #4CAF50; /* 聚焦时边框颜色 */\n"
" outline: none; /* 移除默认的聚焦边框 */\n"
" }\n"
" \n"
" QLineEdit:disabled {\n"
" background-color: #e0e0e0; /* 禁用时背景颜色 */\n"
" color: #808080; /* 禁用时文本颜色 */\n"
" }")
self.lineEdit.setObjectName("lineEdit")
self.gridLayout_2.addWidget(self.lineEdit, 0, 2, 1, 1)
self.label = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正启体简体")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.label.setFont(font)
self.label.setStyleSheet("")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setWordWrap(False)
self.label.setObjectName("label")
self.gridLayout_2.addWidget(self.label, 0, 0, 1, 2)
self.verticalLayout.addLayout(self.gridLayout_2)
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.NoBrush)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.NoBrush)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(170, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(224, 224, 224))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(128, 128, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(224, 224, 224))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(224, 224, 224))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.textBrowser.setPalette(palette)
self.textBrowser.setAutoFillBackground(True)
self.textBrowser.setStyleSheet("\n"
"QTextBrowser {\n"
" border: 2px solid #8f8f91;\n"
" border-radius: 12px; /* 设置圆角半径 */\n"
" padding: 5px;\n"
" background-color: rgba(0, 0, 0, 0);\n"
" color: #000000; \n"
" font: 16pt \"方正大黑简体\";\n"
" }\n"
" \n"
" QTextBrowser:focus {\n"
" border-color: #4CAF50; /* 聚焦时边框颜色 */\n"
" }\n"
" \n"
" QTextBrowser:disabled {\n"
" background-color: #e0e0e0; /* 禁用时背景颜色 */\n"
" color: #808080; /* 禁用时文本颜色 */\n"
" }")
self.textBrowser.setObjectName("textBrowser")
self.verticalLayout.addWidget(self.textBrowser)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
font = QtGui.QFont()
font.setFamily("楷体")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.checkBox.setFont(font)
self.checkBox.setStyleSheet("color:rgb(85, 255, 127);font: 15pt \"楷体\";")
self.checkBox.setChecked(True)
self.checkBox.setTristate(False)
self.checkBox.setObjectName("checkBox")
self.horizontalLayout.addWidget(self.checkBox)
self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_2.setStyleSheet("color:rgb(85, 255, 127);font: 15pt \"楷体\";")
self.checkBox_2.setObjectName("checkBox_2")
self.horizontalLayout.addWidget(self.checkBox_2)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(2)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.NoBrush)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.NoBrush)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(76, 175, 80))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
brush.setStyle(QtCore.Qt.NoBrush)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush)
self.pushButton.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正启体简体")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setUnderline(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton.setFont(font)
self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.pushButton.setStyleSheet("QPushButton {\n"
" border: 2px solid #8f8f91;\n"
" border-radius: 10px; /* 设置圆角半径 */\n"
" background-color: #4CAF50;\n"
" color: black;\n"
" padding: 10px 10px;\n"
" text-align: center;\n"
" text-decoration: none;\n"
" display: inline-block; \n"
" font: 15pt \"方正启体简体\";\n"
" margin: 4px 2px;\n"
" cursor: pointer;\n"
" }\n"
" QPushButton:focus {\n"
" border: 2px solid blue; /* 聚焦时的边框颜色 */\n"
" }\n"
" \n"
" QPushButton:hover {/* 鼠标在他上面时候的颜色 */\n"
" background-color: rgb(255, 0, 0)\n"
" }\n"
" \n"
" QPushButton:pressed {\n"
" background-color: #ff3cfc;\n"
" }")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/jpg/登录 .png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton.setIcon(icon1)
self.pushButton.setIconSize(QtCore.QSize(20, 20))
self.pushButton.setAutoRepeatDelay(200)
self.pushButton.setAutoRepeatInterval(50)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(2)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setFamily("方正卡通简体")
font.setPointSize(15)
font.setBold(False)
font.setItalic(False)
font.setUnderline(False)
font.setWeight(50)
font.setStrikeOut(False)
self.pushButton_3.setFont(font)
self.pushButton_3.setStyleSheet("QPushButton {\n"
" border: 2px solid #8f8f91;\n"
" border-radius: 10px; /* 设置圆角半径 */\n"
" background-color: #00ffff;\n"
" color: black;\n"
" padding: 10px 10px;\n"
" text-align: center;\n"
" text-decoration: none;\n"
" display: inline-block; \n"
" font: 15pt \"方正卡通简体\"; \n"
" margin: 4px 2px;\n"
" cursor: pointer;\n"
" } \n"
" QPushButton:focus {\n"
" border: 2px solid blue; /* 聚焦时的边框颜色 */\n"
" }\n"
" \n"
" QPushButton:hover {/* 鼠标在他上面时候的颜色 */\n"
" background-color: rgb(255, 0, 0)\n"
" }\n"
" \n"
" QPushButton:pressed {\n"
" background-color: #ff3cfc;\n"
" } \n"
" ")
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/jpg/clear.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_3.setIcon(icon2)
self.pushButton_3.setIconSize(QtCore.QSize(20, 20))
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout.addWidget(self.pushButton_3)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setEnabled(True)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(2)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setStyleSheet(" QPushButton {\n"
" border: 2px solid #8f8f91;\n"
" border-radius: 10px; /* 设置圆角半径 */ \n"
" background-color: rgb(255, 85, 0);\n"
" color: black;\n"
" padding: 10px 10px;\n"
" text-align: center;\n"
" text-decoration: none;\n"
" display: inline-block; \n"
" font: 15pt \"方正卡通简体\"; \n"
" margin: 4px 2px;\n"
" cursor: pointer;\n"
" }\n"
"QPushButton:focus {\n"
" border: 2px solid blue; /* 聚焦时的边框颜色 */\n"
" }\n"
" \n"
" QPushButton:hover {/* 鼠标在他上面时候的颜色 */\n"
" background-color: rgb(255, 0, 0)\n"
" }\n"
" \n"
" QPushButton:pressed {\n"
" background-color: #ff3cfc;\n"
" }\n"
"")
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap(":/jpg/退出.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon3)
self.pushButton_2.setIconSize(QtCore.QSize(20, 20))
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar.setProperty("value", 0)
self.progressBar.setTextDirection(QtWidgets.QProgressBar.TopToBottom)
self.progressBar.setObjectName("progressBar")
self.horizontalLayout.addWidget(self.progressBar)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 85, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
self.label_2.setPalette(palette)
font = QtGui.QFont()
font.setFamily("方正舒体简体")
font.setPointSize(20)
font.setBold(False)
font.setItalic(False)
font.setWeight(50)
self.label_2.setFont(font)
self.label_2.setStyleSheet("font: 20pt \"方正舒体简体\";")
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.verticalLayout.addLayout(self.horizontalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.statusBar = QtWidgets.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)
# 自己加的东西
self.label_66 = QtWidgets.QLabel()
self.label_67 = QtWidgets.QLabel()
self.label_66.setText(
"<html><head/><body><p align=\"center\"><span style=\" font-size:15pt;"
"font-family: '方正舒体简体'; color:black;\">制作者:</span><span style=\" font-size:15pt; "
"font-style:italic; color:black;\">Stephen Coopers </span></p></body></html>")
time = QDateTime.currentDateTime()
# timeDisplay = time.toString("HH:mm:ss")
timeDisplay = time.toString("yyyy-MM-dd HH:mm:ss")
self.label_67.setText(timeDisplay)
self.label_67.setStyleSheet("font-size:15pt;color:black;font-style:italic")
self.statusBar.addWidget(self.label_66) # 设置签名
self.statusBar.addWidget(self.label_67) # 设置签名
self.checkBox.setStyleSheet("QCheckBox{ color: red; }") # 设置复选框的文本颜色
self.lineEdit.setValidator(QtGui.QIntValidator())
self.lineEdit_2.setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("^(890|[1-7][0-9]{0,2}|[1-9][0-9]?|0|8[0-8][0-9])$")))
self.retranslateUi(MainWindow)
# 青色边框输入框
aniEdit = AnimationShadowEffect(Qt.cyan, self.lineEdit)
aniEdit_2 = AnimationShadowEffect(Qt.cyan, self.lineEdit_2)
self.lineEdit.setGraphicsEffect(aniEdit)
self.lineEdit_2.setGraphicsEffect(aniEdit_2)
aniEdit.start()
aniEdit_2.start()
# 按钮设置背景动画
self.aniButton = AnimationShadowEffect(Qt.green, self.pushButton)
self.aniButton_2 = AnimationShadowEffect(Qt.yellow, self.pushButton_2)
self.pushButton.setGraphicsEffect(self.aniButton)
self.pushButton_2.setGraphicsEffect(self.aniButton_2)
self.aniButton.start()
self.aniButton_2.start()
self.pushButton.clicked.connect(self.aniButton.stop) # 按下按钮停止动画
self.pushButton.clicked.connect(self.aniButton_2.start) # 按下按钮停止动画
self.pushButton_2.clicked.connect(self.aniButton.stop) # 按下按钮停止动画
# 按钮绑定任务
self.pushButton_2.setVisible(False) # 隐藏发送按钮
self.pushButton_2.clicked.connect(self.slot4) # 停止发送按钮
self.pushButton_2.clicked.connect(self.pushButton.show) # 停止发送按钮
self.pushButton_2.clicked.connect(self.aniButton.start) # 停止发送按钮
self.pushButton_2.clicked.connect(self.pushButton_2.hide) # 停止发送按钮
self.pushButton.clicked.connect(self.start_thread) # type: ignore
self.pushButton.clicked.connect(self.pushButton.hide) # 开始发送按钮
self.pushButton.clicked.connect(self.pushButton_2.show)
self.pushButton_3.clicked.connect(self.slot) # 清除列表按钮
self.pushButton_3.clicked.connect(self.doShake) # 清除列表按钮
self.lineEdit.returnPressed.connect(lambda: self.slot7(MainWindow)) # 房间号输入框使用lambda传参
self.lineEdit_2.returnPressed.connect(lambda: self.slot7(MainWindow)) # 房间号输入框
# self.lineEdit.editingFinished.connect(self.label_3.clear) # type: ignore
self.lineEdit.editingFinished.connect(self.slot2) # type: ignore
self.lineEdit_2.editingFinished.connect(self.slot3) # type: ignore
self.lineEdit_2.textChanged.connect(self.slot3) # type: ignore
self.checkBox_2.stateChanged.connect(self.slot5) # 复选框状态改变
self.checkBox.stateChanged.connect(self.slot5) # 复选框状态改变
# 创建线程实例
self.thread = WorkerThread()
# 连接信号到槽函数
self.thread.middle_signal.connect(self.on_middle)
self.thread.middle_signal2.connect(self.slot6)
self.thread.finished_signal.connect(self.on_finished)
timer = QtCore.QTimer(MainWindow) # 创建一个QTimer计时器对象
timer.timeout.connect(self.showtime) # 发射timeout信号,与自定义槽函数关联
timer.start() # 启动计时器
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "弹幕宠物修炼"))
self.label_3.setText(_translate("MainWindow",
"<html><head/><body><p><span style=\" font-size:18pt; color:#55ffff;\">弹幕发送时间间隔:</span></p></body></html>"))
self.lineEdit_2.setText(_translate("MainWindow", "600"))
self.lineEdit.setText(_translate("MainWindow", "9027467"))
self.label.setText(_translate("MainWindow",
"<html><head/><body><p><span style=\" font-size:22pt; color:#55ffff;\">请输入房间号:</span></p></body></html>"))
self.pushButton.setText(_translate("MainWindow", "开始发送"))
self.pushButton.setShortcut(_translate("MainWindow", "Ctrl+Q"))
self.pushButton_2.setText(_translate("MainWindow", "退出程序"))
self.pushButton_2.setShortcut(_translate("MainWindow", "Ctrl+E"))
self.pushButton_3.setText(_translate("MainWindow", "清除列表"))
self.pushButton_3.setShortcut(_translate("MainWindow", "Ctrl+W"))
self.checkBox_2.setText(_translate("MainWindow", "弹幕宠物"))
self.checkBox.setText(_translate("MainWindow", "猫猫养成"))
self.label_2.setText(
_translate("MainWindow", "<html><head/><body><p align=\"center\"> 等待运行 !</p></body></html>"))
self.textBrowser.setHtml(_translate("MainWindow",
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'楷体\'; font-size:20pt;color: rgb(250, 0, 0); font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">弹幕列表:</p></body></html>"))
def doShake(self):
self.doShakeWindow(self)
# 下面这个方法可以做成这样的封装给任何控件
def doShakeWindow(self, target):
"""窗口抖动动画
:param target: 目标控件
"""
target = MainWindow
print("窗口抖动")
if hasattr(target, '_shake_animation'):
# 如果已经有该对象则跳过
return
animation = QPropertyAnimation(target, b'pos', target)
target._shake_animation = animation
animation.finished.connect(lambda: delattr(target, '_shake_animation'))
pos = target.pos()
x, y = pos.x(), pos.y()
animation.setDuration(200)
animation.setLoopCount(2)
animation.setKeyValueAt(0, QPoint(x, y))
animation.setKeyValueAt(0.09, QPoint(x + 2, y - 2))
animation.setKeyValueAt(0.18, QPoint(x + 4, y - 4))
animation.setKeyValueAt(0.27, QPoint(x + 2, y - 6))
animation.setKeyValueAt(0.36, QPoint(x + 0, y - 8))
animation.setKeyValueAt(0.45, QPoint(x - 2, y - 10))
animation.setKeyValueAt(0.54, QPoint(x - 4, y - 8))
animation.setKeyValueAt(0.63, QPoint(x - 6, y - 6))
animation.setKeyValueAt(0.72, QPoint(x - 8, y - 4))
animation.setKeyValueAt(0.81, QPoint(x - 6, y - 2))
animation.setKeyValueAt(0.90, QPoint(x - 4, y - 0))
animation.setKeyValueAt(0.99, QPoint(x - 2, y + 2))
animation.setEndValue(QPoint(x, y))
animation.start(animation.DeleteWhenStopped)
# 自定义槽函数,用来在状态栏中显示当前日期时间
def showtime(self):
datetime = QtCore.QDateTime.currentDateTime() # 获取当前日期时间
text = datetime.toString("yyyy-MM-dd HH:mm:ss") # 对日期时间进行格式化
self.label_67.setText(text)
def slot(self): # 消除列表按钮
print('正在运行')
# self.textBrowser.clear()
self.textBrowser.setHtml(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'楷体\'; font-size:20pt;color: rgb(250, 0, 0); font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">弹幕列表:</p></body></html>")
def slot2(self):
print('房间号:', self.lineEdit.text())
def slot3(self): # 更新弹幕发送的延时时间
print(self.lineEdit_2.text())
global delay
delay = int(self.lineEdit_2.text())
def slot4(self): # 停止发送
global do_work, do_work2
# self.slot6(percentage)
do_work = False
do_work2 = False
# 设置 QLabel 的样式表以改变字体颜色
self.label_2.setStyleSheet("color: red;")
self.label_2.setText('等待运行!')
def slot5(self): # 复选框发生改变
print('slot5——复选框发生改变')
if self.checkBox.isChecked():
self.lineEdit.setText('9027467')
# 设置复选框的文本颜色
self.checkBox.setStyleSheet("QCheckBox{ color: red; }")
else:
self.checkBox.setStyleSheet('QCheckBox{ color:rgb(85, 255, 127);font: 15pt "楷体"; }')
if self.checkBox_2.isChecked():
self.lineEdit.setText('3941627')
self.checkBox_2.setStyleSheet("QCheckBox{ color: red; }")
else:
self.checkBox_2.setStyleSheet('QCheckBox{ color:rgb(85, 255, 127);font: 15pt "楷体"; }')
print(self.lineEdit.text())
def slot6(self, percent): # 更新进度条百分比
self.progressBar.setValue(percent)
def slot7(self, MainWindow): # 为房间号文本输入框的按下回车信号绑定的槽函数,获取用户输入的房间号
print("为房间号文本输入框的按下回车信号绑定的槽函数,获取用户输入的房间号")
try: # 限制只能输入数字
name, ok = QInputDialog.getText(MainWindow, "房间号", "请输入房间号", QtWidgets.QLineEdit.Normal,
self.sender().text(),
flags=Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint,
inputMethodHints=Qt.ImhDigitsOnly)
if name.isdecimal():
print("ok")
if ok: # 判断是否单击了OK按钮
self.sender().setText(name) # 获取输入对话框中的字符串,显示在文本框中
else:
QMessageBox.critical(MainWindow, "提示", "仅仅可以输入数字\n", QMessageBox.No)
except Exception as e:
print(e)
def start_thread(self):
global do_work
do_work = True
# 启动线程
self.label_2.setStyleSheet("color: black;")
self.label_2.setText('下一条弹幕发送!')
roomId = self.lineEdit.text()
if (roomId != '9027467') & (roomId != '3941627'):
print('这里')
reply = QtWidgets.QMessageBox.question(self, 'Tips',
"选择弹幕宠物还是猫猫养成,Yes弹幕宠物,No猫猫养成",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
self.checkBox.setChecked(True) # 将复选框设置为选中状态
self.checkBox_2.setChecked(False) # 将复选框设置为选中状态
else:
self.checkBox.setChecked(False) # 将复选框设置为选中状态
self.checkBox_2.setChecked(True) # 将复选框设置为选中状态
if not self.thread.isRunning():
print('main id', QThread.currentThread())
self.thread.start() # 启动线程
def on_middle(self, message): # 线程中间的处理
print("Thread middle")
self.send()
self.label.setText(message)
def on_finished(self): # 线程完成后的处理
print("Thread finished!")
self.label.setText("<font color=white> Thread finished! </font>")
def updateUi(self, message):
try:
text = ' '
message += text
color = random.choice(color_list)
self.textBrowser.append(f"<pre><br> <font color={color}>{message} </font></br></pre>") # 显示内容支撑html格式语法
except:
self.textBrowser.append("<font color=red>%s is invalid!</font>" % message)
def send(self): # 发送弹幕
global a, do_work2, do_work
# print('do_work2:', do_work2)
try:
roomId = self.lineEdit.text()
if (not a) | (not do_work2):
# print('-'*100)
if self.checkBox.isChecked():
send_meg = '修仙'
if roomId == "9027467":
self.send2(send_meg, roomId)
elif roomId == "3941627":
self.send2(send_meg, "9027467")
else:
# self.send2(send_meg, "9027467")
self.send2(send_meg, roomId)
return
if self.checkBox_2.isChecked():
send_meg = '喵'
if roomId == "3941627":
self.send2(send_meg, roomId)
elif roomId == "9027467":
self.send2(send_meg, "3941627")
else:
# self.send2(send_meg, "3941627")
self.send2(send_meg, roomId)
if not self.checkBox.isChecked() and not self.checkBox_2.isChecked():
QMessageBox.information(MainWindow, "提示", "请选择弹幕宠物或者猫猫养成复选框\n", QMessageBox.Ok)
do_work = False
return
do_work2 = True
else:
if self.checkBox.isChecked():
send_meg = random.choice(lis_text2)
if roomId == "9027467":
self.send2(send_meg, roomId)
elif roomId == "3941627":
self.send2(send_meg, "9027467")
else:
# self.send2(send_meg, "9027467")
self.send2(send_meg, roomId)
return
if self.checkBox_2.isChecked():
send_meg = random.choice(lis_text)
if roomId == "3941627":
self.send2(send_meg, roomId)
elif roomId == "9027467":
self.send2(send_meg, "3941627")
else:
# self.send2(send_meg, "3941627")
self.send2(send_meg, roomId)
if not self.checkBox.isChecked() and not self.checkBox_2.isChecked():
QMessageBox.information(self, "提示", "请选择弹幕宠物或者猫猫养成复选框\n", QMessageBox.Ok)
do_work = False
return
except Exception as e:
print(e)
def send2(self, send_meg, roomId):
global a
url = 'https://api.live.bilibili.com/msg/send'
data = {
'bubble': '0',
'msg': send_meg,
'color': '16777215',
'mode': '1',
'room_type': '0',
'jumpfrom': '71001',
'reply_mid': '0',
'reply_attr': '0',
'replay_dmid': '',
'statistics': {"appId": '100', "platform": '5'},
'reply_type': '0',
'reply_uname': '',
'fontsize': '25',
'rnd': '1740058543',
'roomId': '{}'.format(roomId),
'csrf': '2528ac1f0f7b633cfbfb8266bebee3a9', # 新账号需要改这里
'csrf_token': '2528ac1f0f7b633cfbfb8266bebee3a9', # 新账号需要改这里
}
headers = {
# 新账号需要改cookie
# 'Cookie': "LIVE_BUVID=AUTO3516048326950470; buvid4=F5CB8C85-EEDA-07B6-0ADB-2ABB06DD39CE49140-022000211-YdCYHOtTw2Bn6Oi19MWYqg%3D%3D; rpdid=|(J~R)ulJk)u0J'uY~|J)~YYR; header_theme_version=CLOSE; home_feed_column=5; buvid3=4BCA90A2-9358-E481-15AE-497383D8CBC213436infoc; b_nut=1709956413; _uuid=EB811DB5-D10B1-10F58-1B102-EDEE10D4AC5F608283infoc; enable_web_push=DISABLE; FEED_LIVE_VERSION=V_DYN_LIVING_UP; buvid_fp_plain=undefined; fingerprint=13c9bc59234d5413350808d6341b65e8; is-2002-channel=1; CURRENT_BLACKGAP=0; CURRENT_FNVAL=4048; buvid_fp=13c9bc59234d5413350808d6341b65e8; browser_resolution=1874-939; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1724755652,1724950044; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjYyMjI2ODYsImlhdCI6MTcyNTk2MzQyNiwicGx0IjotMX0.WfTZ3D5AiBmSrAC1e7GFYoEeu_q--HZoTrKANaZeyX0; bili_ticket_expires=1726222626; SESSDATA=381c5870%2C1741515493%2C1400a%2A91CjBm99GTeYTNHMC4ta63srvHW6SmQfzCbdZHtwCRefSuFenDNumOhdv0AZSLC77xBA4SVnNZNU12ZnNDME1RUFZKQlphQzRKcWtWeDdLVERYR1RpWno0RmMwLVp0Q1R2YUJwQ2x4OFlBSUpiVjktYVFXUTBIY2d6cTIyN2tsdHVpSC1TX0k4T3FBIIEC; bili_jct=4cb23f0382a5c1d8bda997b24f5be710; sid=860njx69; b_lsid=CAEEFC13_191E0F40007; PVID=2",
'Cookie': "buvid3=0A929476-B840-32B4-3F5C-3C6C0B162D4648875infoc; b_nut=1725698848; _uuid=E43FA16A-72C10-BA32-81010B-6DC10A197CABB51096infoc; buvid4=C8FA3BCA-213C-F996-DFE4-2123F12CD24451628-024090708-CWDZBzdYGHaDiK77MGDu0g%3D%3D; enable_web_push=DISABLE; header_theme_version=CLOSE; home_feed_column=5; LIVE_BUVID=AUTO5917277516958839; rpdid=|(umRYkkJlYu0J'u~k~~lkYR|; DedeUserID=17648823; DedeUserID__ckMd5=9c54a0d0505112ab; fingerprint=43a705ca1a3b90fb189ed920a459f118; buvid_fp_plain=undefined; buvid_fp=43a705ca1a3b90fb189ed920a459f118; browser_resolution=1872-947; CURRENT_FNVAL=4048; b_lsid=2445CF36_1952388E654; enable_feed_channel=DISABLE; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDAzMTcxMzAsImlhdCI6MTc0MDA1Nzg3MCwicGx0IjotMX0.dP_FVHq8Ah5kiuHxfrc_IR0iQdXq6_mWm57ouQkGlwI; bili_ticket_expires=1740317070; SESSDATA=48db11f9%2C1755609930%2Ceff3b%2A21CjDIEx3oG3BUGWrQ28v-KJ1x7BD6epmoXwv2neP8vN_cYIBqnGRspJJnW_O3OYGnZ0YSVkprMDZfRFZnd3h1NW5YS2lXTkt4SG92SFhDekdZazcwTGNzMGw1bGhEUlZXV1dfYkFKQ19OY19MRG1QN3hTcFFlRGtaOXdYdE1iVkhqVVhKcGE0dk13IIEC; bili_jct=2528ac1f0f7b633cfbfb8266bebee3a9; sid=7ee7u806; Hm_lvt_8a6e55dbd2870f0f5bc9194cddf32a02=1740057957; Hm_lpvt_8a6e55dbd2870f0f5bc9194cddf32a02=1740057957; HMACCOUNT=B1D0AE8C1B766655; PVID=4",
'origin': 'https://live.bilibili.com',
'referer': 'https://live.bilibili.com/blanc/1029?liteVersion=true',
'Sec - Ch - Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
'Sec - Ch - Ua - Mobile': '?0',
'Sec - Ch - Ua - Platform': '"Windows"',
'Sec - Fetch - Dest': 'empty',
'Sec - Fetch - Mode': 'cors',
'Sec - Fetch - Site': 'same - site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
a += 1
# print(roomId)
try:
response = requests.post(url=url, data=data, headers=headers, timeout=10)
print('大号斯蒂芬', response, end='\t')
except HTTPError:
print('httperror')
self.updateUi(
f'第{a}条弹幕发送失败,房间号:{roomId},发送内容:{send_meg}。' + '错误原因:httperror')
except RequestException:
print('reqerror')
self.updateUi(
f'第{a}条弹幕发送失败,房间号:{roomId},发送内容:{send_meg}。错误原因:reqerror')
except ReadTimeout:
print('time out')
self.updateUi(
f'第{a}条弹幕发送失败,房间号:{roomId},发送内容:{send_meg}。错误原因:time out')
except Exception as e:
print(e)
self.updateUi(f'第{a}条弹幕发送失败,房间号:{roomId},发送内容:{send_meg}。错误原因:{str(e)}')
else:
self.updateUi(f'第{a}条弹幕发送成功,房间号:{roomId},发送内容:{send_meg}。')
# 必须添加第二个类来继承添加窗口属性不然报错AttributeError: 'Ui_MainWindow' object has no attribute 'geometry'
class Agent(Ui_MainWindow, QtWidgets.QWidget, ):
def center(self):
# 获得屏幕坐标系
screen = QDesktopWidget().screenGeometry()
# 获得窗口坐标系
size = self.geometry()
# 获得窗口相关坐标
newLeft = (screen.width() - size.width()) // 2
newTop = (screen.height() - size.height()) // 2
# 移动窗口使其居中
self.move(newLeft, newTop)
class Ui_MainWindow(Agent):
pass
class QMainWindow(QtWidgets.QMainWindow):
"""对QMainWindow类重写,实现一些功能"""
def closeEvent(self, event):
"""重写closeEvent方法,实现dialog窗体关闭时执行一些代码
:param event: close()触发的事件
:return: None
"""
reply = QtWidgets.QMessageBox.question(self,
'本程序',
"是否要退出程序?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes:
event.accept()
if self.thread.isRunning():
self.thread.requestInterruption()
self.thread.quit()
self.thread.wait()
# 强制
# self._thread.terminate()
self.thread.deleteLater()
else:
event.ignore()
TextStyle = """
QMessageBox QPushButton {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FF6B6B, stop:1 #FF8E8E);
color: white;
border: none;
border-radius: 10px;
padding: 10px 20px;
}
QInputDialog QPushButton {
background: transparent;
color: #008CBA;
border: 2px solid #008CBA;
border-radius: 5px;
padding: 8px 16px;
}
QInputDialog QPushButton:hover {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #008CBA, stop:1 #006699);
color: white;
}
QMessageBox QPushButton:hover {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FF5252, stop:1 #FF7F7F);
}
QMessageBox QPushButton:pressed {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FF3D3D, stop:1 #FF6B6B);
}
QMessageBox QPushButton:hover {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FF5252, stop:1 #FF7F7F);
}
QMessageBox QPushButton:pressed {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FF3D3D, stop:1 #FF6B6B);
}
QMessageBox QPushButton[text="OK"] {
qproperty-text: "好";
}
QInputDialog QPushButton[text="OK"] {
qproperty-text: "是";
}
QMessageBox QPushButton[text="Open"] {
qproperty-text: "打开";
}
QMessageBox QPushButton[text="Save"] {
qproperty-text: "保存";
}
QMessageBox QPushButton[text="Cancel"] {
qproperty-text: "取消";
}
QInputDialog QPushButton[text="Cancel"] {
qproperty-text: "不";
}
QMessageBox QPushButton[text="Close"] {
qproperty-text: "关闭";
}
QMessageBox QPushButton[text="Discard"] {
qproperty-text: "不保存";
}
QMessageBox QPushButton[text="Don't Save"] {
qproperty-text: "不保存";
}
QMessageBox QPushButton[text="Apply"] {
qproperty-text: "应用";
}
QMessageBox QPushButton[text="Reset"] {
qproperty-text: "重置";
}
QMessageBox QPushButton[text="Restore Defaults"] {
qproperty-text: "恢复默认";
}
QMessageBox QPushButton[text="Help"] {
qproperty-text: "帮助";
}
QMessageBox QPushButton[text="Save All"] {
qproperty-text: "保存全部";
}
QMessageBox QPushButton[text="&Yes"] {
qproperty-text: "是";
}
QInputDialog QPushButton[text="&Yes"] {
qproperty-text: "是";
}
QMessageBox QPushButton[text="Yes to &All"] {
qproperty-text: "全部都是";
}
QMessageBox QPushButton[text="&No"] {
qproperty-text: "不";
}
QMessageBox QPushButton[text="N&o to All"] {
qproperty-text: "全部都不";
}
QMessageBox QPushButton[text="Abort"] {
qproperty-text: "终止";
}
QMessageBox QPushButton[text="Retry"] {
qproperty-text: "重试";
}
QMessageBox QPushButton[text="Ignore"] {
qproperty-text: "忽略";
}
"""
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv) # 实例化QApplication类,作为GUI主程序入口
# 通过QSS样式的方式设置按钮文字
app.setStyleSheet(TextStyle)
MainWindow = QMainWindow() # 注意修改为了自己重写的QMainWindow类
MainWindow.setStyleSheet("#MainWindow{background-color:#C0E6FF}") # 设置背景颜色
ui = Ui_MainWindow() # 实例化ui类
ui.setupUi(MainWindow) # 设置窗口UI
ui.center() # 调用方法使窗口居中
MainWindow.show() # 显示窗口
sys.exit(app.exec_()) # 当窗口创建完成时,需要结束主循环过程