Python程序运行1次后中断



感谢大家的帮助,现在已经修复了。

问题是在我得到我的cps计数后,程序延迟并冻结。它停止显示cps。

我不知道为什么会发生这种情况,也不知道如何解决它。该程序是一个cps计数器,它工作后,我尝试,然后它打破并冻结,如果我使用它第二次。

我也不知道代码在哪里中断了,非常感谢。

代码如下:

import threading
from tkinter import *
import time
clicks = 0
cps = 0
start = True
wn = Tk()
wn.title("Cps Counter")
wn.geometry("400x300")
def cps5():
global start
global cps
global clicks
global t1
start = False
time.sleep(5)
cps = (clicks / 5)
clicks = 0 
CpsButton.config(text=clicks)
CpsAmount.config(text=cps)
start = True
time.sleep(.1
t1 = threading.Thread(target=cps5)
t1.start()
def AddClicks():
global clicks
global start
clicks += 1
CpsButton.config(text=clicks)
if start == True:
cps5()
CpsButton = Button(wn, text=clicks, command=AddClicks, pady=15, padx=15)
CpsAmount = Label(wn, text=cps, pady=15, padx=15)
CpsAmount.pack()
CpsButton.pack()
wn.mainloop()

import threading
from tkinter import *
import time
clicks = 0
cps = 0
start = True
wn = Tk()
wn.title("Cps Counter")
wn.geometry("400x300")
clicks = 0
def cps5():
global start
global cps
global clicks
global t1
start = False
CpsButton.config(text=clicks)
start = True


def AddClicks():
global clicks
global start
clicks += 1
CpsButton.config(text=clicks)
if start == True:
cps5()
CpsButton = Button(wn, text=clicks, command=AddClicks, pady=15, padx=15)
CpsAmount = Label(wn, text=cps, pady=15, padx=15)
CpsAmount.pack()
CpsButton.pack()

def Timer():
global CpsAmount, cps, clicks
for i in range(0, 5):
time.sleep(1)
cps = (clicks / 5)
CpsAmount.config(text=cps)
clicks = 0
Timer()
t1 = threading.Thread(target=cps5)
t1.start()
t2 = threading.Thread(target=Timer)
t2.start()
wn.mainloop()

我为计数器创建了第二个线程,因为时间。睡眠会使程序冻结并引起麻烦。

最新更新