'피드'를 중지하는 데 문제가 있습니다. cancel 인수는 after 메서드에 영향을 미치지 않는 것 같습니다. "피드 중지됨"이 콘솔에 인쇄되지만.기능 후에 tkinter를 중지하려면 어떻게합니까?
피드를 시작하는 버튼 하나와 피드를 중지시킬 버튼이 하나 있습니다. 출력과
from Tkinter import Tk, Button
import random
def goodbye_world():
print "Stopping Feed"
button.configure(text = "Start Feed", command=hello_world)
print_sleep(True)
def hello_world():
print "Starting Feed"
button.configure(text = "Stop Feed", command=goodbye_world)
print_sleep()
def print_sleep(cancel=False):
if cancel==False:
foo = random.randint(4000,7500)
print "Sleeping", foo
root.after(foo,print_sleep)
else:
print "Feed Stopped"
root = Tk()
button = Button(root, text="Start Feed", command=hello_world)
button.pack()
root.mainloop()
: 당신이 root.after(...)
를 호출 할 때
Starting Feed
Sleeping 4195
Sleeping 4634
Sleeping 6591
Sleeping 7074
Stopping Feed
Sleeping 4908
Feed Stopped
Sleeping 6892
Sleeping 5605
tkinter의 작동 방식에 대해서는 완전히 확신 할 수 없지만이 문제는 나에게 스레딩 문제와 매우 유사합니다. a (thread safe) 전역을 취소 할 경우 문제가 해결됩니까? – mklauber
@mklauber : 아니오, 스레딩 문제가 아닙니다. Tkinter는 단일 스레드입니다. –
@BryanOakley : 감사합니다. 이것이 제가 코멘트로 올린 이유입니다. 나는 그 질문을 제기하기를 원했기 때문에 확실하지 않았다. – mklauber