나는 멈출 때까지 매초 울리는이 프로그램을 가지고있다. 문제는 "시작"을 누르고 신호음이 울리면 창이 정지되어 "중지"버튼을 클릭 할 수 없다는 것입니다. 어떤 도움도 환영합니다.TKinter - 중지 버튼을 사용하여 루프를 중지하는 방법?
#!/usr/bin/python
import Tkinter, tkMessageBox, time, winsound, msvcrt
running = True
Freq = 2500
Dur = 150
top = Tkinter.Tk()
top.title('MapAwareness')
top.geometry('200x100') # Size 200, 200
def start():
sec = 0
while running:
if sec % 1 == 0:
winsound.Beep(Freq, Dur)
time.sleep(1)
sec += 1
def stop():
running = False
startButton = Tkinter.Button(top, height=2, width=20, text ="Start", command = start)
stopButton = Tkinter.Button(top, height=2, width=20, text ="Stop", command = stop)
startButton.pack()
stopButton.pack()
top.mainloop()
실행 단지 동안 할 경우 실행하는 동안 그냥 뭔가를 그냥 계속 실행, 하나 if 문 while 루프 내부에 추가됩니다 그래서 거짓 실행하는 동안으로 실행하거나 할 것 == 참. – Elxafil