Python Pyinstaller exe打开tkinter窗口的多个实例,Python Firebase [视频] [英] Python Pyinstaller exe opens multiple instance of tkinter window, Python Firebase [Video]

查看:99
本文介绍了Python Pyinstaller exe打开tkinter窗口的多个实例,Python Firebase [视频]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剪贴脚本,其中我使用tkinter用于ui.当我用exeinstaller构建exe(并使用pyinstaller)并很好地打开它时,但是当我关闭它时,它会打开tkinter Window的多个实例.我无法粘贴完整的代码.所以我粘贴了我正在使用的所有tkinter代码.

I have a scrapping script of where im using tkinter for ui. When i build the exe(with pyinstaller) and open it it working well, But When i close it, it opens multiple instance of tkinter Window. I cant paste the full code. So i pasted all the tkinter code i am using.

这是完整代码 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 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库.在初始化中,有close_process_pool()函数,该函数在程序退出并关闭所有多处理池时调用.在tkinter和pyqt情况下,我们不需要此函数,因为所有过程都是主GUI线程的子进程,因此只需删除该函数即可解决问题. 将初始化文件更改为此将解决问题.

i was facing the exact the same problem with firebase and pyqt5. After many tries i examine the firebase library. In init there is close_process_pool() function which is called when program exits and close all the multiprocessing pools. In tkinter and pyqt case we dont need this function as all the process is the childs of main GUI thread so simple removing that function resolves the problem. Change the init file to this will resolve the issue.

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()
    '''

这篇关于Python Pyinstaller exe打开tkinter窗口的多个实例,Python Firebase [视频]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆