【发布时间】:2021-04-22 15:46:17
【问题描述】:
我正在制作一个目前正在播放的歌曲,但问题是我试图每隔几秒钟更新一次当前播放的歌曲,但它总是说'(1400,'GetClassName','无效的窗口句柄。')'每当它更新
from SwSpotify import spotify
from plyer import notification
import time
from watchpoints import watch
song = spotify.song()
artist = spotify.artist()
message = ''
message_check = message
loop = True
title = 'Currently Playing'
def notif():
message= '%s by %s' % (song,artist)
notification.notify(title= title,message= message,app_icon = None,timeout= 10,toast=False)
print('notif sent')
while True:
song = spotify.song()
artist = spotify.artist()
print (message + '1')
print (message_check + '2')
message= '%s by %s' % (song,artist)
if message != message_check:
notif()
message_check = message
continue
else:
time.sleep(1)
continue
【问题讨论】:
-
你不需要写
continue,循环自动继续,除非while条件失败或者你使用break。continue仅在您想在到达正文末尾之前开始下一次迭代时才需要。 -
请发布完整的回溯。你的代码从不调用
GetClassName(),所以不清楚发生在哪里。 -
@barmar 我使用 continue 导致循环失败并且没有它就不会重新运行
-
发生异常:错误 (1400, 'GetClassName', 'Invalid window handle.') 文件“C:\Users\hyper\Documents\better spotify\gui.py”,第 17 行,在
艺术家 = spotify.artist() -
你想找哪首歌的艺术家?
标签: python python-3.x spotify