python tkinter Tcl_AsyncDelete: async handler deleted by the wrong thread
我是解决不了了~~~
当我尝试从主窗口tkinter窗口打开另一个窗口时,我收到此错误,第一次它运行良好并且也执行任务,但是在2次之后它给出了此错误,整个程序崩溃并关闭没有任何警告,我不知道如何在python中处理此错误,如果有任何错误处理技术,请帮助我, 就我而言,我只是从主tkinter窗口调用另一个tkinter窗口,我已经非常努力地解决了这个错误,但它没有得到解决,因为它一次又一次地出现,尝试了以前帖子中给出的所有方法。还是不行
弹出的窗体,代码如下:
import ctypes
import inspect
import os
import random
import threading
import tkinter
import time
import pygame
from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
from framework.control.AdenButton import AdenButton
from framework.control.AdenLabel import AdenLabel
from framework.control.AdenTkPlugin import TkPlugin
from framework.pulgin.Tools import Tools
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class ApsMonitorAlarmClock():
def __init__(self):
# do this before importing pylab or pyplot
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
pass
def job(self):
# tkinter简单示例源码
import tkinter as tk
# 调用Tk()创建主窗口
self.window = tk.Tk()
self.window.wm_attributes('-topmost', 1)
self.window.configure(background=TkPlugin.background())
self.window.rowconfigure(0, weight=1)
self.window.rowconfigure(3, weight=1)
self.window.columnconfigure(0, weight=1)
# 第1行
self.lable_void1 = AdenLabel(self.window)
self.lable_void1.grid(row=0, column=0, sticky=TkPlugin.sticky_all())
# 第2行
self.lable_message = AdenLabel(self.window, text="L2打个人", font='Helvetica -30 bold')
self.lable_message.config(fg="#D9534F")
self.lable_message.grid(row=1, column=0, sticky=TkPlugin.sticky_all())
# 第3行
self.lable_time = AdenLabel(self.window, text="2021-11-11 9:37:20", font='Helvetica -30 bold')
self.lable_time.grid(row=2, column=0, sticky=TkPlugin.sticky_all())
# 第4行
self.lable_void1 = AdenLabel(self.window)
self.lable_void1.grid(row=3, column=0, sticky=TkPlugin.sticky_all())
# 第5行
btn_stop = AdenButton(self.window, text="停止音乐", width=8, command=lambda: self.stop())
btn_stop.grid(row=4, column=0, sticky=tkinter.E, padx="70")
btn_close = AdenButton(self.window, text="关闭闹钟", bg="#D9534F", width=8, command=lambda: self.close())
btn_close.grid(row=4, column=0, sticky=tkinter.E)
screenWidth = self.window.winfo_screenwidth() # 屏幕宽度
screenHeight = self.window.winfo_screenheight() # 屏幕高度
w=400
h=300
x=screenWidth-w-20
y=screenHeight-h-80
# 设置窗口大小和位置:窗口的宽与高,窗口距离屏幕的左边距和上边距
self.window.geometry("%dx%d+%d+%d" % (w, h, x, y))
# 给窗口起一个名字,也就是窗口的名字
self.window.title("亚丁号闹钟")
#
# T = threading.Thread(target=self.music, args=())
# T.setDaemon(True)
# T.start()
self.update_clock()
# 开启主循环,让窗口处于显示状态
self.window.mainloop()
def music(self):
music_array=["精灵村.mp3","猎人村.mp3","说话岛.mp3","芙罗兰村庄.mp3"
,"水上都市海因斯.mp3","奇岩城镇.mp3","古鲁丁村庄.mp3","亚丁城镇.mp3"
,"命运的召唤.mp3","CrossroadAtDawn.mp3","AfterTheStorm.mp3"]
index=random.randint(0, len(music_array)-1)
#file = Tools.get_resource_mp3_path() + os.sep + music_array[index]
file = "D:\\Code\\Python\\AdenHunter\\framework\\resource\\mp3" + os.sep + music_array[index]
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play(loops=10) # pygame.mixer.music.play(-1)
while pygame.mixer.music.get_busy(): # 在音频播放为完成之前不退出程序
pass
def builder_aps_task(self):
scheduler = BlockingScheduler(timezone='Asia/Shanghai')
scheduler.add_job(self.job, 'cron', day="*", hour="8", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="10", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="12", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="14", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="16", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="18", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="20", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="22", minute="55")
scheduler.add_job(self.job, 'cron', day="*", hour="21", minute="45")
scheduler.add_job(self.job, 'cron', day="*", hour="21", minute="46")
scheduler.add_job(self.job, 'cron', day="*", hour="21", minute="47")
scheduler.start()
def stop(self):
pygame.mixer.music.stop()
def close(self):
#pygame.mixer.music.stop()
self.window.destroy()
pass
def update_clock(self):
now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
self.lable_time['text'] = '{0}'.format(now_time)
self.window.after(1000, self.update_clock)
def show(self):
self.T = threading.Thread(target=self.__show, args=())
self.T.setDaemon(True)
self.T.start()
def __show(self):
while 1:
now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
self.lable_time['text'] = '{0}'.format(now_time)
time.sleep(1)
if __name__ == "__main__":
ApsMonitorAlarmClock().job()
#ApsMonitorAlarmClock().builder_aps_task()
pass
关闭2 次就会报错。
Tcl_AsyncDelete: async handler deleted by the wrong thread
我试验了各种办法就是不行。
wxpython
pyqt5
都不行,这个应该是python的超级大BUG