# -*- coding: utf-8 -*-
"""
将耗时间的任务放到线程中以获得更好的用户体验。
"""
import time
import tkinter
import tkinter.messagebox


def download():
    # 模拟下载任务需要花费10秒时间
    time.sleep(10)
    tkinter.messagebox.showinfo('提示', '下载完成')


def show_about():
    tkinter.messagebox.showinfo('关于', '作者：罗浩')


def main():
    top = tkinter.Tk()
    top.title('单线程')
    top.geometry('200x150')
    top.wm_attributes('-topmost', True)

    panel = tkinter.Frame(top)
    button1 = tkinter.Button(panel, text='下载', command=download)
    button1.pack(side='left')
    button2 = tkinter.Button(panel, text='关于', command=show_about)
    button2.pack(side='right')
    panel.pack(side='bottom')

    tkinter.mainloop()


if __name__ == '__main__':
    main()

[(12, 'time.sleep', 'time.sleep', False, 'import time\n'), (13, 'tkinter.messagebox.showinfo', 'tkinter.messagebox.showinfo', False, 'import tkinter\n'), (17, 'tkinter.messagebox.showinfo', 'tkinter.messagebox.showinfo', False, 'import tkinter\n'), (21, 'tkinter.Tk', 'tkinter.Tk', False, 'import tkinter\n'), (26, 'tkinter.Frame', 'tkinter.Frame', False, 'import tkinter\n'), (27, 'tkinter.Button', 'tkinter.Button', False, 'import tkinter\n'), (29, 'tkinter.Button', 'tkinter.Button', False, 'import tkinter\n'), (33, 'tkinter.mainloop', 'tkinter.mainloop', False, 'import tkinter\n')]