Re: [問題]tkinter-button 點擊只管執行function就好
※ 引述《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://www.ptt.cc/bbs/Python/M.1412750638.A.43C.html
→
10/08 23:10, , 1F
10/08 23:10, 1F
→
10/09 13:56, , 2F
10/09 13:56, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):