Python Pyinstaller EXE打开了TKINTER窗口的多个实例,Python Firebase [Vid



我有一个刮擦脚本,即我在哪里使用tkinter为UI。当我构建EXE(使用Pyinstaller(并将其打开良好时,但是当我关闭它时,它将打开TKINTER窗口的多个实例。我无法粘贴完整的代码。因此,我粘贴了我正在使用的所有TKINTER代码。

这是此处的完整代码github要点

import requests
from lxml import html
from tkinter import *
import tkinter as ttk
import re
import datetime
import os
from firebase import firebase
import hashlib
#import App as App
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

#Region Tk
root = Tk()
root['height'] = 400
root['width'] = 600
global firebase
firebase = firebase.FirebaseApplication('#######URL####',None)
f1 = Frame(root)
f1["height"] = root["height"]
f1["width"] = root["width"]
root.title("JD Scraper - Gear Up Studio ")
Label(f1,text = "Input Url : Example : https://www.justdial.com/Ahmedabad/Gyms ").grid(row=0,column = 0,)
def getBool(event):
    print(boolvar.get())
#Check Button
global boolvar
boolvar = BooleanVar()
boolvar.set(False)
boolvar.trace('w', lambda *_: print("The value was changed"))
cb = Checkbutton(f1, text = "Tele Phone number", variable = boolvar)
cb.bind("<Button-1>", getBool)
cb.grid(row=1, column=1)
global key_filled
key_filled = Entry(f1,width=50)
key_filled.grid(row=2,column=0)
key_filled.focus_set()
global activate_button
activate_button = Button(f1 , text="Active Now")
activate_button.bind("<Button-1>",activate_key)
activate_button.grid(row=2, column=1)

result = Label(f1, width=50)
result.grid(row=1,column=2)
global submit_button
submit_button = Button(f1 , text="Scrape Now")
submit_button.bind("<Button-1>",button_clicked)
submit_button.grid(row=1, column=0)
submit_button.config(state=NORMAL)
key_validation()
f1.pack()
root.mainloop()

演示视频在这里

我正面临着firebase和pyqt5的同样问题。经过多次尝试,我检查了火库库。在INIT中,有CLOSS_PROCESS_POOL((函数,当程序退出并关闭所有多处理池时称为。在TKINTER和PYQT情况下,我们不需要此功能,因为所有过程都是Main GUI线程的孩子,因此简单删除功能可以解决该问题。将初始文件更改为此将解决问题。

import atexit
#from .async import process_pool
from firebase import *

'''
@atexit.register
def close_process_pool():
    """
    Clean up function that closes and terminates the process pool
    defined in the ``async`` file.
    """
    process_pool.close()
    process_pool.join()
    process_pool.terminate()
    '''

我可以在运行 exe时看到 cmd窗口pops使用此命令 -w,并将其作为单文件汇编为dist文件夹使用 -F将其编译为单个文件,请执行此操作。解决问题

pyinstaller -w -F replace this with your script name.py

它将将文件作为您的一个文件编译为您,并且使用将用于res

最新更新