Python Asyncio/Tkinter RuntimeWarning:启用tracemalloc以获取对象分配回溯
我曾尝试使用Tkinter和Asyncio打开一些智能指示灯。我的计划是使用一个按钮,当点击时会把灯变成红色。但我一直在犯这样的错误:Python Asyncio/Tkinter RuntimeWarning:启用tracemalloc以获取对象分配回溯,python,tkinter,python-asyncio,Python,Tkinter,Python Asyncio,我曾尝试使用Tkinter和Asyncio打开一些智能指示灯。我的计划是使用一个按钮,当点击时会把灯变成红色。但我一直在犯这样的错误: C:\Users\rcbsa\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py:603: RuntimeWarning: coroutine 'redButton.changeToRed' was never awaited _get_default_root('run the ma
C:\Users\rcbsa\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py:603: RuntimeWarning: coroutine 'redButton.changeToRed' was never awaited
_get_default_root('run the main loop').tk.mainloop(n)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
我只编写了8个月的代码,如果我的代码有点混乱,我深表歉意,但这里是:
import asyncio, time
from pywizlight import wizlight, PilotBuilder, discovery
import tkinter
from tkinter import *
main_window = tkinter.Tk()
main_window.geometry("600x500+1280+20")
main_window.title("Red")
class redButton:
async def changeToRed(self):
await light.turn_on(PilotBuilder(rgb = (255, 0, 0)))
await light2.turn_on(PilotBuilder(rgb = (255, 0, 0)))
loop = asyncio.get_event_loop()
loop.run_until_complete(self.changeToRed(self))
def __init__(self):
self.light = wizlight([IP REDACTED])
self.light2 = wizlight([IP REDACTED])
self.main_frame = Frame(main_window, width=600, height=500)
self.red_button = Button(self.main_frame,
text = "Red",
command = self.changeToRed)
self.red_button.pack()
self.main_frame.pack()
tkinter.mainloop()
redButton()
我猜想它与changeToRed函数中的循环变量有关。
是的,灯的IP已经修改过了