※ 引述《arnold0613 (凯)》之铭言:
: button按下后 会去呼叫function并且等function执行完毕
: 有什么方法可以不要等functionr结束 只管去呼叫就好
: 因为我的funciotn是无限循环 需要用另一个button去关闭
以下是我的程式 现在可以关闭但是用浏览进去会发生一直等待
可以提供点意见吗
import http.server
import socketserver
import threading
import tkinter
PORT = 9000
Handler = http.server.SimpleHTTPRequestHandler
server = socketserver.TCPServer(("", PORT), Handler)
server_thread= threading.Thread(target=server.serve_forever)
server_thread.daemon = True
def stopServer():
server.shutdown()
target.clear()
def openServer():
print("serving at port",PORT)
server_thread.start()
view = tkinter.Tk()
startButton=tkinter.Button(view, text ="开启Server", command = openServer)
startButton.pack()
stopButton = tkinter.Button(view, text ="停止Server", command = stopServer)
stopButton.pack()
view.mainloop()