2

I have a scraping 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.

Here is the Full code Github Gist here

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

Demo Video here

Arun K
  • 868
  • 10
  • 17
  • 2
    upvoted just because of OP taking time to add a video – Jean-François Fabre Feb 08 '18 at 09:52
  • 2
    Yeah good effort on the video but the code provided should still really be trimmed down to the minimum, I'm not sure all those widgets and configurations are absolutely necessary to reproduce the problem. – eugenhu Feb 08 '18 at 10:04
  • Here is the full code : [click here](https://gist.github.com/arunkarnann/a96c63ae03d3bfab85fe811e3dd1f241) Hope this helps – Arun K Feb 08 '18 at 10:09
  • 1
    now the full code doesn't interest us as much... if you can, try to create a self-contained example that everyone can run ([mcve]) if you can avoid selenium or other third-party packages that's even better. – Jean-François Fabre Feb 08 '18 at 10:15
  • 1
    Thanks for asking me to minimal code. I tried to reduce the code and i found out where the problem is. its `from firebase import firebase` including just this line makes it multiple instance opening.. But just need to why its is behaving like that . – Arun K Feb 08 '18 at 10:36
  • [Firebase issue](https://github.com/ozgur/python-firebase/issues/48) need Main function to solve the isssue – Arun K Feb 08 '18 at 10:40
  • How is this solved? – Delrius Euphoria Aug 21 '20 at 22:43
  • The accepted answer worked for me. Please check that. – Arun K Aug 22 '20 at 10:48

2 Answers2

1

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()
    '''
Luqman
  • 66
  • 1
  • 5
0

I can see cmd window pops when run your exe to remove that use this command -w and also to compile as onefile into dist folder use -F to compile it as a single file, do this to resolve the issue

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

It will compile the file as one file for you and the use will be res

AD WAN
  • 1,414
  • 2
  • 15
  • 28
  • Tried it . It creates a single `jd.exe` file. When i open there is `cmd` but still closing that window open multiple instance of it. – Arun K Feb 08 '18 at 10:06
  • yes , like this i builded `pyinstaller -w -F E:\OutSourceWorks\jd2\jd.py` – Arun K Feb 08 '18 at 10:12
  • when you run code in your ide does the cmd window pops – AD WAN Feb 08 '18 at 10:14
  • Nope i am using Sublime text its all good there . No command window. – Arun K Feb 08 '18 at 10:19
  • create a folder on your desktop and copy your code then compile and let see the result – AD WAN Feb 08 '18 at 10:22
  • Thanks for the Answer. I tried to reduce the code and i found out where the problem is. its `from firebase import firebase` including just this line makes it multiple instance opening.. But just need to why its is behaving like that . Its working well without firebase. – Arun K Feb 08 '18 at 10:36