使用pyinstaller或其他任何工具将py编译为exe后,是否只能在特定时间激活控制台?

时间:2019-04-20 07:09:59

标签: python cmd pyinstaller

我正在用python构建一个程序,该程序将使用robocopy复制大文件。由于gui在复制完成后冻结,因此我只有两个选择: 1.了解如何执行多线程并设计GUI以显示进度而不是冻结。 2.使用pyinstaller编译后,可以保持控制台打开,以替代在gui冻结时显示robocopy进度。

我愿意进行多线程处理,但是我是一个初学者,很难理解如何为robocopy制作另一个子流程,然后从中将进度提取到gui中的标签中。我想到的选项是仅在复制完成时才使cmd控制台处于活动状态。可能吗?情况将是这样的:

  1. 打开程序(控制台将被隐藏)
  2. 按下复制按钮(在gui冻结时控制台会弹出并显示复制进度)
  3. 复制完成后,再次隐藏控制台

正如我上面所说。我并不完全排除添加多线程的问题,但为此我需要一些帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

请尝试使用此代码,应该可以运行,如果出现问题,请告诉我:

import tkinter as tk
import os
import subprocess
import threading


main = tk.Tk()
main.title('Title')
frame_main = tk.Frame(main)
frame_main.grid(columnspan=1)

src = 'D:/path/to/the/folder'
dest = 'D:/path/to/the/folder2'
selection_platf = len(os.name)


def copy_build_button():
    if selection_platf < 11:
        subprocess.call(["robocopy", src, dest, r"/XF", 'BT V_SyncPackage.zip', "/S"])
    else: #for linux
        subprocess.call(["robocopy", src, dest, "/S"])


def copy_thread():
    thread_1 = threading.Thread(target=copy_build_button)
    thread_1.start()


button_main1 = tk.Button(frame_main, text="copy_build_button", width=50, height=5, fg="green", command=copy_thread)
button_main1.grid(column=0, sticky='N'+'S'+'E'+'W')

main.mainloop()