我一直在这堂课中得到一个无限循环,而这次肯定来自.ExNote()
,但我不知道为什么。我把它简化了,所以你去了:
class Note():
x=[0]
y=[0]
def __init__(self, Num, staff, note, notetype):
self.staff = staff
self.note = note
self.notetype = notetype
self.Num=Num
def ExNote(self):
screen.blit(self.notetype, (self.x[self.Num], self.y[self.Num]))
print('exnote')
going = True
while going:
screen.fill(white)
Note(0, '0R', '40', EthnoteIMG).ExNote()
returrns
exnote
exnote
exnote.....
为什么在执行此功能后它不会停止?
答案 0 :(得分:1)
"去的时候:"是一个循环。它需要在循环内设置为False才能停止它。只需要显示的代码,就不需要while循环,可以完全删除。你说你只显示了一部分代码,所以我会让你决定何时应该停止循环。
class Note():
x=[0]
y=[0]
def __init__(self, Num, staff, note, notetype):
self.staff = staff
self.note = note
self.notetype = notetype
self.Num=Num
def ExNote(self):
screen.blit(self.notetype, (self.x[self.Num], self.y[self.Num]))
print('exnote')
going = True
while going:
screen.fill(white)
Note(0, '0R', '40', EthnoteIMG).ExNote()
if <your stop condition>:
going = False # You need to set going to False inside your loop to get it to stop
OR
going = <some function that returns false when appropriate>
答案 1 :(得分:-2)
请在代码末尾插入一个中断功能
虽然是真的: Bla blabla Blablabla 破
那应该杀了它