cx_freeze tkinter应用程序无法在Windows中使用多处理

时间:2018-03-08 00:30:52

标签: windows selenium tkinter multiprocessing cx-freeze

我创建了一个基本的Tkinter GUI,它有一个按钮,当你点击它时,它应该使用多处理来打开5个Chrome实例" https://www.google.com。"当我使用cx_freeze编译脚本时,我点击新的exe,按钮什么都不做。这是代码:

main.py

from tkinter import *
from selenium import webdriver
import os, multiprocessing
import numpy as np

def func():
    print("bot started")

    home = "https://www.google.com" 

    chromeOptions = webdriver.ChromeOptions()

    user_txt_path = []

    user_txt_path.append('\\chromedriver.exe')

    filename = os.path.dirname(sys.argv[0])
    path_to_chromedriver = str(os.path.abspath(filename) + user_txt_path[0])

    driver = webdriver.Chrome(chrome_options=chromeOptions, executable_path=path_to_chromedriver) #DRIVER DRIVER!
    driver.get_cookies()

    driver.get(home)

def callback():
    num = 5
    for n in np.arange(num):
        p = multiprocessing.Process(target=func)
        p.start()

master = Tk()

b = Button(master, text="OK", command=callback)
b.pack()

mainloop()

setup.py

from cx_Freeze import setup, Executable
import sys
import os
from pathlib import Path

user_txt_path = []

base = "Console"#"Win32GUI"
user_txt_path.append('chromedriver.exe')
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

buildOptions = {"include_files": [user_txt_path[0], 'tcl86t.dll', 'tk86t.dll'], "packages": ['encodings', "os"], "includes": ['numpy.core._methods', 'numpy.lib.format'], "excludes": []}

executables = [
    Executable('main.py', base=base)
]

home_path = str(Path.home())
pathname = str(os.path.dirname(sys.argv[0]))

setup(name='numbers',
      version = '1.0',
      #description = 'test',
      #shortcutName="TachySloth",
      #shortcutDir="DesktopFolder",
      options = dict(build_exe = buildOptions),
      executables = executables
      )

请注意,您需要使用main.py。

在父目录中包含所有include_files

0 个答案:

没有答案