Re: [問題]tkinter-button 點擊只管執行function就好

看板Python作者 (凱)時間9年前 (2014/10/08 14:43), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《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/09 13:56, , 2F
太感謝了
10/09 13:56, 2F
文章代碼(AID): #1KDDqkGy (Python)
文章代碼(AID): #1KDDqkGy (Python)