# -*- 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()

[((164, 178), 'time.sleep', 'time.sleep', (['(10)'], {}), '(10)\n', (174, 178), False, 'import time\n'), ((184, 225), 'tkinter.messagebox.showinfo', 'tkinter.messagebox.showinfo', (['"""提示"""', '"""下载完成"""'], {}), "('提示', '下载完成')\n", (211, 225), False, 'import tkinter\n'), ((254, 296), 'tkinter.messagebox.showinfo', 'tkinter.messagebox.showinfo', (['"""关于"""', '"""作者：罗浩"""'], {}), "('关于', '作者：罗浩')\n", (281, 296), False, 'import tkinter\n'), ((325, 337), 'tkinter.Tk', 'tkinter.Tk', ([], {}), '()\n', (335, 337), False, 'import tkinter\n'), ((445, 463), 'tkinter.Frame', 'tkinter.Frame', (['top'], {}), '(top)\n', (458, 463), False, 'import tkinter\n'), ((479, 529), 'tkinter.Button', 'tkinter.Button', (['panel'], {'text': '"""下载"""', 'command': 'download'}), "(panel, text='下载', command=download)\n", (493, 529), False, 'import tkinter\n'), ((576, 628), 'tkinter.Button', 'tkinter.Button', (['panel'], {'text': '"""关于"""', 'command': 'show_about'}), "(panel, text='关于', command=show_about)\n", (590, 628), False, 'import tkinter\n'), ((699, 717), 'tkinter.mainloop', 'tkinter.mainloop', ([], {}), '()\n', (715, 717), False, 'import tkinter\n')]