MCPcopy
hub / github.com/ZiniuLu/Python-100-Days / main

Function main

Day01-15/Day13/multithread4.py:17–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def main():
18
19 class DownloadTaskHandler(Thread):
20
21 def run(self):
22 # 模拟下载任务需要花费10秒钟时间
23 time.sleep(10)
24 tkinter.messagebox.showinfo('提示', '下载完成!')
25 # 启用下载按钮
26 button1.config(state=tkinter.NORMAL)
27
28 def download():
29 # 禁用下载按钮
30 button1.config(state=tkinter.DISABLED)
31 # 通过daemon参数将线程设置为守护线程(主程序退出就不再保留执行)
32 DownloadTaskHandler(daemon=True).start()
33
34 def show_about():
35 tkinter.messagebox.showinfo('关于', '作者: 骆昊(v1.0)')
36
37 top = tkinter.Tk()
38 top.title('单线程')
39 top.geometry('200x150')
40 top.wm_attributes('-topmost', 1)
41
42 panel = tkinter.Frame(top)
43 button1 = tkinter.Button(panel, text='下载', command=download)
44 button1.pack(side='left')
45 button2 = tkinter.Button(panel, text='关于', command=show_about)
46 button2.pack(side='right')
47 panel.pack(side='bottom')
48
49 tkinter.mainloop()
50
51
52if __name__ == '__main__':

Callers 1

multithread4.pyFile · 0.70

Calls 1

titleMethod · 0.80

Tested by

no test coverage detected