繁体   English   中英

Python Pyinstaller exe 打开多个 tkinter 窗口实例,Python Firebase [视频]

[英]Python Pyinstaller exe opens multiple instance of tkinter window, Python Firebase [Video]

我有一个我在 ui 中使用 tkinter 的地方的报废脚本。 当我构建 exe(使用 pyinstaller)并打开它时它运行良好,但是当我关闭它时,它会打开 tkinter 窗口的多个实例。 我不能粘贴完整的代码。 所以我粘贴了我正在使用的所有 tkinter 代码。

这里是完整的代码Github Gist

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 Scrapper - 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="Scrap 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 完全相同的问题。 经过多次尝试,我检查了 firebase 库。 在 init 中有 close_process_pool() 函数,该函数在程序退出并关闭所有多处理池时调用。 在 tkinter 和 pyqt 的情况下,我们不需要这个函数,因为所有进程都是主 GUI 线程的子进程,所以简单地删除该函数就可以解决问题。 将 init 文件更改为此将解决此问题。

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窗口弹出,使用此命令删除该命令-w并将作为 onefile 编译到 dist 文件夹中使用-F将其编译为单个文件,执行此操作以解决问题

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

它将为您编译该文件作为一个文件,使用将是 res

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM