作者arnold0613 (凯)
看板Python
标题Re: [问题]tkinter-button 点击只管执行function就好
时间Wed Oct 8 14:43:55 2014
※ 引述《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()
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.170.165.134
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1412750638.A.43C.html
2F:→ arnold0613: 太感谢了 10/09 13:56