|
10鱼币
本帖最后由 cjjJasonchen 于 2023-7-21 10:30 编辑
- <blockquote><div class="blockcode"><blockquote>""" 这个版本是专门用来体验的,如果要追求性能请调节SpurtFire的timer"""
- import pygame
- import sys
- import random
- import ttkbootstrap as tk
- import ttkbootstrap.constants as tkc
- from pygame.locals import *
- class Particle(pygame.sprite.Sprite):
- def __init__(self,color=(255,255,255),position=[0,0],radius=0,speed=[0,0],time=-1):
- super().__init__()
- self.position = position
- self.image = pygame.Surface([radius*2,radius*2]).convert_alpha()
- self.rect = self.image.get_rect()
- self.rect.centerx,self.rect.centery = position[0],position[1]
- self.color = color
- self.radius = radius
- self.speed = speed
- self.time = time
- pygame.draw.rect(self.image,(0,0,0,0),[0,0,radius * 2,radius * 2])
-
- def update(self):
- self.time -= 1
- self.rect.centerx += self.speed[0]
- self.rect.centery += self.speed[1]
- pygame.draw.circle(self.image,
- color=self.color,
- center=(self.radius,self.radius),
- radius=self.radius)
- class SpurtFire(Particle):
- def __init__(self, position,
- color=[255,255,255,255],
- time=[45,120],
- speed=[[-2,2],[-2,-2]],
- num = 4,
- radius=[1,4],
- burn_time=600,
- timer = 0):
- self.particles = pygame.sprite.Group()
- self.position = position
- self.color = color
- self.time = time
- self.speed = speed
- self.num = num
- self.radius = radius
- self.burn_time = burn_time
- self.timer0 = timer
- self.timer = timer
- def update(self):
- self.particles.update()
- for i in self.particles:
- if i.time == 0:
- self.particles.remove(i)
- i.speed = [random.randint(self.speed[0][0],self.speed[0][1]),random.randint(self.speed[1][0],self.speed[1][1])]
- i.color[3] = self.color[3]/self.time[1]*i.time
- if self.timer == 0:
- self.timer = self.timer0
- self.create_particle()
- else:
- self.timer -= 1
- self.burn_time -= 1
-
- def draw(self,screen):
- self.particles.draw(screen)
-
- def create_particle(self):
- for i in range(self.num):
- self.particles.add(Particle(color=self.color.copy(),
- position=[self.position[0],self.position[1]],
- radius=random.randint(self.radius[0],self.radius[1]),
- speed=[random.randint(self.speed[0][0],self.speed[0][1]),random.randint(self.speed[1][0],self.speed[1][1])],
- time = random.randint(self.time[0],self.time[1])
- )
- )
-
- def set_up():
- color = {"outside":[85,85,85,20],
- "inside":[170,170,170,10],
- "core":[255,255,255,10],
- "bg":[0,0,0]}
- num_list = [50,25,12]
- size = [1,10]
-
-
- root = tk.Window(themename="superhero")
- root.geometry("700x700+300+10")
- tk.Label(root, text="请输入外焰、內焰和焰芯的颜色",font=("楷体", 30)).pack(padx=5,pady=10)
- key_l = tk.Label(root, text="点它!——> (红)(绿)(蓝)(透明度) <——点它!",font=("楷体", 15))
- key_l.pack(padx = 5,pady = 5)
- frame1 = tk.Frame(root,width = 400,height = 300)
- frame1.pack(padx=5,pady=5)
- tk.Label(frame1, text="",font=("楷体", 40)).grid(row=0,column=0)
- # 外焰
- tk.Label(frame1, text="外焰颜色(RGBA):(",font=("楷体", 20)).grid(row=1,column=0)
-
- outer_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e1.grid(row=1,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=2)
- outer_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e2.grid(row=1,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=4)
-
- outer_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e3.grid(row=1,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=6)
- outer_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e4.grid(row=1,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=1,column=8)
-
-
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=2,column=0)
- # 内焰
- tk.Label(frame1, text="内焰颜色(RGBA):(",font=("楷体", 20)).grid(row=3,column=0)
-
- inside_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e1.grid(row=3,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=2)
- inside_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e2.grid(row=3,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=4)
-
- inside_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e3.grid(row=3,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=6)
- inside_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e4.grid(row=3,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=3,column=8)
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=4,column=0)
- # 焰芯
- tk.Label(frame1, text="焰芯颜色(RGBA):(",font=("楷体", 20)).grid(row=5,column=0)
-
- core_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e1.grid(row=5,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=2)
- core_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e2.grid(row=5,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=4)
-
- core_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e3.grid(row=5,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=6)
- core_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e4.grid(row=5,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=5,column=8)
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=6,column=0)
- # 粒子数量
- num = tk.IntVar()
- num.set(50)
-
- particel_num = tk.StringVar()
- particel_num.set(f"粒子数量:外焰{int(num.get())}、內焰{int(num.get()/2)}、焰芯{int(num.get()/4)}")
-
- tk.Label(frame1, textvariable=particel_num, font=("楷体", 20)).grid(row=7, column=0,columnspan=7)
- tk.Label(frame1, text="少",style="primary", font=("楷体", 15)).grid(row=8,column=0)
- tk.Label(frame1, text="多",style="primary", font=("楷体", 15)).grid(row=8,column=7)
- def change_particle_num(event):
- particel_num.set(f"粒子数量:外焰{int(num.get())}、內焰{int(num.get()/2)}、焰芯{int(num.get()/4)}")
-
- num_s = tk.Scale(frame1, from_=10, to=80, length=300, variable=num,command=change_particle_num)
- num_s.grid(row=8,column=0,columnspan=7,padx=5,pady=5,sticky="e")
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=9,column=0)
- # 粒子大小
- tk.Label(frame1, text="粒子数量:", font=("楷体", 20)).grid(row=10, column=0)
- tk.Label(frame1, text="最小:",style="primary", font=("楷体", 15)).grid(row=10,column=1)
- tk.Label(frame1, text="最大:",style="primary", font=("楷体", 15)).grid(row=10,column=4)
- size_e1 = tk.Entry(frame1, width=3,font=("楷体", 15))
- size_e1.grid(row=10,column=2,padx=5,pady=5,sticky="e")
- size_e2 = tk.Entry(frame1, width=3,font=("楷体", 15))
- size_e2.grid(row=10,column=5,padx=5,pady=5)
-
- # 背景
- tk.Label(frame1, text="背景\n更改\n |\n ﹀",style="primary").grid(row=0,column=9)
-
- tk.Button(frame1, text="白",style="light").grid(row=10,column=9,padx=10)
- tk.Button(frame1, text="黑",style="secondary").grid(row=1,column=9,padx=10)
-
- bg_s = tk.Scale(frame1, from_=0, to=255, orient=tk.VERTICAL, length=300,style="light")
- bg_s.grid(row=1,rowspan=10,column=9,padx=30,pady=10)
-
- # 确定
- def return_color():
- try:
- color["outside"] = [int(outer_e1.get()),int(outer_e2.get()),int(outer_e3.get()),int(outer_e4.get())]
- color["inside"] = [int(inside_e1.get()),int(inside_e2.get()),int(inside_e3.get()),int(inside_e4.get())]
- color["core"] = [int(core_e1.get()),int(core_e2.get()),int(core_e3.get()),int(core_e4.get())]
- color["bg"] = [int(bg_s.get()),int(bg_s.get()),int(bg_s.get())]
- num_list[0]=int(num_s.get())
- num_list[1]=int(num_s.get()/2)
- num_list[2]=int(num_s.get()/4)
- size[0]=int(size_e1.get())
- size[1]=int(size_e2.get())
- except:
- pass
- root.destroy()
-
-
- tk.Style().configure('my.TButton', font=('楷体', 35))
- b = tk.Button(root, text='确定', style='my.TButton',command=return_color)
- b.pack(padx=10,pady = 20,fill="both")
- root.mainloop()
- return color,num_list,size
- if __name__ == "__main__":
- size = width, height = 800,600
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption("title")
- clock = pygame.time.Clock()
- delay = 60 # 延时计时器
- time = 0
- # 是否全屏
- fullscreen = False
- screen_change = False
- running = True
- # 粒子效果列表
- particles = []
- # 颜色,数量,大小
- color = {"outside":[0,0,255,30],
- "inside":[0,255,255,10],
- "core":[200,200,255,10],
- "bg":[0,0,0]}
- num = [80,40,20]
- particle_size = [1,10]
- while running:
- clock.tick(60)
- # 得到鼠标位置
- pos = pygame.mouse.get_pos()
- # 检测是否全屏
- if fullscreen and screen_change:
- screen = pygame.display.set_mode(size,FULLSCREEN,HWSURFACE)
- screen_change = False
- elif screen_change:
- screen = pygame.display.set_mode(size)
- screen_change = False
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
-
- if event.type == MOUSEBUTTONDOWN:
- if event.button == 1:
- particles.append(SpurtFire(pos,
- color=color["outside"],
- time=[1,80],
- speed=[[-3,+3],[-2,-1]],
- num = num[0],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
- particles.append(SpurtFire(pos,
- color=color["inside"],
- time=[1,70],
- speed=[[-2,+2],[-2,-1]],
- num = num[1],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
- particles.append(SpurtFire(pos,
- color=color["core"],
- time=[1,50],
- speed=[[-1,+1],[-2,-1]],
- num = num[2],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
-
-
- if event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- pygame.quit()
- sys.exit()
-
- #F11切换全屏
- elif event.key == K_F11:
- fullscreen = not fullscreen
- screen_change = True
- elif event.key == K_1:
- bg = (255,255,255)
- elif event.key == K_2:
- bg = (0,0,0)
- elif event.key == K_o:
- color,num,particle_size=set_up()
- pygame.event.clear()
-
- elif event.key == K_c:
- particles.clear()
- #画背景
- screen.fill(color["bg"])
- #画 xxxx
- for particle in particles:
- particle.draw(screen)
- #刷新
- for particle in particles:
- particle.update()
- if not particle.burn_time:
- particles.remove(particle)
- # 刷新界面
- pygame.display.update()
复制代码
点击o会生成一个ttk界面,但是从第二次开始他的风格变得不一样了,看起来像tkinter的默认主题
再补充一下,主题看起来是对的,但是组件的风格看起来不对,上图:
正常的
第二次开始
我寻思这可能就是ttk自己有问题啊。。。
看看这个:
- import ttkbootstrap as ttk
- class A():
- def __init__(self):
-
- #input("回车创建窗口")
- self.root=ttk.Window()
- self.root.geometry("700x700+300+10")
- ttk.Button(self.root,text="关闭",command=self.callback).pack()
- self.root.mainloop()
- print(1)
- def callback(self):
- self.root.destroy()
-
- if __name__ == "__main__":
- A()
- A()
复制代码
明明是一样的,我甚至没有设置主题。。。为什么两次出来的不一样
- import pygame
- import sys
- import random
- import tkinter as tkinter
- import ttkbootstrap as tk
- import ttkbootstrap.constants as tkc
- from pygame.locals import *
- from threading import Thread, current_thread
- class Particle(pygame.sprite.Sprite):
- def __init__(self,color=(255,255,255),position=[0,0],radius=0,speed=[0,0],time=-1):
- super().__init__()
- self.position = position
- self.image = pygame.Surface([radius*2,radius*2]).convert_alpha()
- self.rect = self.image.get_rect()
- self.rect.centerx,self.rect.centery = position[0],position[1]
- self.color = color
- self.radius = radius
- self.speed = speed
- self.time = time
- pygame.draw.rect(self.image,(0,0,0,0),[0,0,radius * 2,radius * 2])
-
- def update(self):
- self.time -= 1
- self.rect.centerx += self.speed[0]
- self.rect.centery += self.speed[1]
- pygame.draw.circle(self.image,
- color=self.color,
- center=(self.radius,self.radius),
- radius=self.radius)
- class SpurtFire(Particle):
- def __init__(self, position,
- color=[255,255,255,255],
- time=[45,120],
- speed=[[-2,2],[-2,-2]],
- num = 4,
- radius=[1,4],
- burn_time=600,
- timer = 0):
- self.particles = pygame.sprite.Group()
- self.position = position
- self.color = color
- self.time = time
- self.speed = speed
- self.num = num
- self.radius = radius
- self.burn_time = burn_time
- self.timer0 = timer
- self.timer = timer
- def update(self):
- self.particles.update()
- for i in self.particles:
- if i.time == 0:
- self.particles.remove(i)
- i.speed = [random.randint(self.speed[0][0],self.speed[0][1]),random.randint(self.speed[1][0],self.speed[1][1])]
- i.color[3] = self.color[3]/self.time[1]*i.time
- if self.timer == 0:
- self.timer = self.timer0
- self.create_particle()
- else:
- self.timer -= 1
- self.burn_time -= 1
-
- def draw(self,screen):
- self.particles.draw(screen)
-
- def create_particle(self):
- for i in range(self.num):
- self.particles.add(Particle(color=self.color.copy(),
- position=[self.position[0],self.position[1]],
- radius=random.randint(self.radius[0],self.radius[1]),
- speed=[random.randint(self.speed[0][0],self.speed[0][1]),random.randint(self.speed[1][0],self.speed[1][1])],
- time = random.randint(self.time[0],self.time[1])
- )
- )
- # 颜色,数量,大小
- color = {"outside":[0,0,255,30],
- "inside":[0,255,255,10],
- "core":[200,200,255,10],
- "bg":[0,0,0]}
- num = [80,40,20]
- particle_size = [1,10]
- def set_up():
- global root
- color = {"outside":[85,85,85,20],
- "inside":[170,170,170,10],
- "core":[255,255,255,10],
- "bg":[0,0,0]}
- num_list = [50,25,12]
- size = [1,10]
-
-
- root = tk.Window(themename="superhero")
-
- root.geometry("700x700+300+10")
- root.update()
-
- tk.Label(root, text="请输入外焰、內焰和焰芯的颜色",font=("楷体", 30)).pack(padx=5,pady=10)
- key_l = tk.Label(root, text="点它!——> (红)(绿)(蓝)(透明度) <——点它!",font=("楷体", 15))
- key_l.pack(padx = 5,pady = 5)
- frame1 = tk.Frame(root,width = 400,height = 300)
- frame1.pack(padx=5,pady=5)
- tk.Label(frame1, text="",font=("楷体", 40)).grid(row=0,column=0)
- # 外焰
- tk.Label(frame1, text="外焰颜色(RGBA):(",font=("楷体", 20)).grid(row=1,column=0)
-
- outer_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e1.grid(row=1,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=2)
- outer_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e2.grid(row=1,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=4)
-
- outer_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e3.grid(row=1,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=1,column=6)
- outer_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- outer_e4.grid(row=1,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=1,column=8)
-
-
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=2,column=0)
- # 内焰
- tk.Label(frame1, text="内焰颜色(RGBA):(",font=("楷体", 20)).grid(row=3,column=0)
-
- inside_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e1.grid(row=3,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=2)
- inside_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e2.grid(row=3,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=4)
-
- inside_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e3.grid(row=3,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=3,column=6)
- inside_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- inside_e4.grid(row=3,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=3,column=8)
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=4,column=0)
- # 焰芯
- tk.Label(frame1, text="焰芯颜色(RGBA):(",font=("楷体", 20)).grid(row=5,column=0)
-
- core_e1 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e1.grid(row=5,column=1)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=2)
- core_e2 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e2.grid(row=5,column=3)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=4)
-
- core_e3 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e3.grid(row=5,column=5)
- tk.Label(frame1, text=")(",font=("楷体", 20)).grid(row=5,column=6)
- core_e4 = tk.Entry(frame1,width=3,font=("楷体", 20),bootstyle="PRIMARY")
- core_e4.grid(row=5,column=7)
- tk.Label(frame1, text=")",font=("楷体", 20)).grid(row=5,column=8)
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=6,column=0)
- # 粒子数量
- num = tk.IntVar()
- num.set(50)
-
- particel_num = tk.StringVar()
- particel_num.set(f"粒子数量:外焰{int(num.get())}、內焰{int(num.get()/2)}、焰芯{int(num.get()/4)}")
-
- tk.Label(frame1, textvariable=particel_num, font=("楷体", 20)).grid(row=7, column=0,columnspan=7)
- tk.Label(frame1, text="少",style="primary", font=("楷体", 15)).grid(row=8,column=0)
- tk.Label(frame1, text="多",style="primary", font=("楷体", 15)).grid(row=8,column=7)
- def change_particle_num(event):
- particel_num.set(f"粒子数量:外焰{int(num.get())}、內焰{int(num.get()/2)}、焰芯{int(num.get()/4)}")
-
- num_s = tk.Scale(frame1, from_=10, to=80, length=300, variable=num,command=change_particle_num)
- num_s.grid(row=8,column=0,columnspan=7,padx=5,pady=5,sticky="e")
- tk.Label(frame1, text="",font=("楷体", 30)).grid(row=9,column=0)
- # 粒子大小
- tk.Label(frame1, text="粒子数量:", font=("楷体", 20)).grid(row=10, column=0)
- tk.Label(frame1, text="最小:",style="primary", font=("楷体", 15)).grid(row=10,column=1)
- tk.Label(frame1, text="最大:",style="primary", font=("楷体", 15)).grid(row=10,column=4)
- size_e1 = tk.Entry(frame1, width=3,font=("楷体", 15))
- size_e1.grid(row=10,column=2,padx=5,pady=5,sticky="e")
- size_e2 = tk.Entry(frame1, width=3,font=("楷体", 15))
- size_e2.grid(row=10,column=5,padx=5,pady=5)
-
- # 背景
- tk.Label(frame1, text="背景\n更改\n |\n ﹀",style="primary").grid(row=0,column=9)
-
- tk.Button(frame1, text="白",style="light").grid(row=10,column=9,padx=10)
- tk.Button(frame1, text="黑",style="secondary").grid(row=1,column=9,padx=10)
-
- bg_s = tk.Scale(frame1, from_=0, to=255, orient=tk.VERTICAL, length=300,style="light")
- bg_s.grid(row=1,rowspan=10,column=9,padx=30,pady=10)
-
- # 确定
- def return_color():
- try:
- global color,num,particle_size
- color["outside"] = [int(outer_e1.get()),int(outer_e2.get()),int(outer_e3.get()),int(outer_e4.get())]
- color["inside"] = [int(inside_e1.get()),int(inside_e2.get()),int(inside_e3.get()),int(inside_e4.get())]
- color["core"] = [int(core_e1.get()),int(core_e2.get()),int(core_e3.get()),int(core_e4.get())]
- color["bg"] = [int(bg_s.get()),int(bg_s.get()),int(bg_s.get())]
- num_list[0]=int(num_s.get())
- num_list[1]=int(num_s.get()/2)
- num_list[2]=int(num_s.get()/4)
- size[0]=int(size_e1.get())
- size[1]=int(size_e2.get())
- # outer_e1.set()
- except:
- pass
- root.withdraw()
- # root.update()
- # root.protocol("WM_DELETE_WINDOW", on_closing)
- # root.destroy()
- # if not root:
- # return
-
-
- tk.Style().configure('my.TButton', font=('楷体', 35))
- b = tk.Button(root, text='确定', style='my.TButton',command=return_color)
- b.pack(padx=10,pady = 20,fill="both")
- root.mainloop()
- # root_L.mainloop()
-
- if_start = 0
- if __name__ == "__main__":
- size = width, height = 800,600
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption("title")
- clock = pygame.time.Clock()
- delay = 60 # 延时计时器
- time = 0
- # 是否全屏
- fullscreen = False
- screen_change = False
- running = True
- # 粒子效果列表
- particles = []
- while running:
- clock.tick(60)
- # 得到鼠标位置
- pos = pygame.mouse.get_pos()
- # 检测是否全屏
- if fullscreen and screen_change:
- screen = pygame.display.set_mode(size,FULLSCREEN,HWSURFACE)
- screen_change = False
- elif screen_change:
- screen = pygame.display.set_mode(size)
- screen_change = False
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- # root.destroy()
- exit()
-
- if event.type == MOUSEBUTTONDOWN:
- if event.button == 1:
- particles.append(SpurtFire(pos,
- color=color["outside"],
- time=[1,80],
- speed=[[-3,+3],[-2,-1]],
- num = num[0],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
- particles.append(SpurtFire(pos,
- color=color["inside"],
- time=[1,70],
- speed=[[-2,+2],[-2,-1]],
- num = num[1],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
- particles.append(SpurtFire(pos,
- color=color["core"],
- time=[1,50],
- speed=[[-1,+1],[-2,-1]],
- num = num[2],
- radius = particle_size,
- burn_time = 1200,
- timer=0))
-
-
- if event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- pygame.quit()
- root.destroy()
- sys.exit()
-
- #F11切换全屏
- elif event.key == K_F11:
- fullscreen = not fullscreen
- screen_change = True
- elif event.key == K_1:
- bg = (255,255,255)
- elif event.key == K_2:
- bg = (0,0,0)
- elif event.key == K_o:
- # color,num,particle_size=thread01=Thread(target=set_up, name="线程1")
- if (if_start == 0):
- thread01=Thread(target=set_up, name="线程1")
- thread01.start()
- if_start = 1
- else:
- root.update()
- root.deiconify()
- pygame.event.clear()
-
- elif event.key == K_c:
- particles.clear()
- #画背景
- screen.fill(color["bg"])
- #画 xxxx
- for particle in particles:
- particle.draw(screen)
- #刷新
- for particle in particles:
- particle.update()
- if not particle.burn_time:
- particles.remove(particle)
- # 刷新界面
- pygame.display.update()
-
复制代码
使用多线程来解决这个办法
然后再打开还会保留上一次的数据,你自己写把内容清空就行了
如果对你有帮助的话,给个最佳答案呗!!!
|
最佳答案
查看完整内容
使用多线程来解决这个办法
然后再打开还会保留上一次的数据,你自己写把内容清空就行了
如果对你有帮助的话,给个最佳答案呗!!!
|