'Multiproccessed chromedrivers causes the build of my tkinter programme to open extra tkinter windows
I have a very basic tkinter programme (basically i want to be able to run a few detatched multiproccesed chromedrivers at the click of a button.) it all works fine in idle, but when i use cx_freeze to make a build it behaves differently.
When i click go on the build version, it opens a brand new tkinter window and also runs the chromedriver functions. this also happens when i run the programme in cmd line instead of idle. but in idle its all fine, it simply runs the functions without opening a new window.
Script
from selenium.webdriver.support.ui import WebDriverWait
import selenium.webdriver.chrome.options as Options
from selenium import webdriver
import time
from tkinter import *
from multiprocessing import Process
def open_a_page(): # open one chromedriver in detatched mode (because i specifically want it to stay open when finished)
driver_xpath2 = "chromedriver.exe"
chrome_options = Options.Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(driver_xpath2 ,options=chrome_options )
driver.get("https://www.google.com")
print("yo ")
time.sleep(2)
def open_2_pages():
processes = []
for i in range(2):
p1 = Process( target = open_a_page , args = ())
processes.append(p1)
for proc in processes:
proc.start()
for proc in processes:
proc.join()
print("done ")
window=Tk()
B = Button(window, text ="go", command = open_2_pages) # when i click this button it opens 2 googles
B.place(x=10, y=10);
if __name__ == '__main__':
window.mainloop();
I want my build / command line, to work just like it does in idle. What have i done wrong here?
UPDATE
I tried to simplify the problem further by removing chrome driver from the equation, however this fixed the problem. so i think chromedriver is to blame.
import time
from tkinter import *
from multiprocessing import Process
def dothing(): # do a thing
print("yo ")
def open_2_things():
processes = []
for i in range(2):
p1 = Process( target = dothing , args = ())
processes.append(p1)
for proc in processes:
proc.start()
for proc in processes:
proc.join()
print("done ")
window=Tk()
B = Button(window, text ="go", command = open_2_things) # when i click this button it do 2 things
B.place(x=10, y=10);
if __name__ == '__main__':
window.mainloop();
How can i make my original program work with multiproccesed detatched chromedrivers without it opening additional tkinter windows?
update 2
I have removed the multiproccesing, but left in the chromedriver, this also fixes the problem.
from selenium.webdriver.support.ui import WebDriverWait
import selenium.webdriver.chrome.options as Options
from selenium import webdriver
import time
from tkinter import *
def open_a_page(): # open one chromedriver in detatched mode (because i specifically want it to stay open when finished)
driver_xpath2 = "chromedriver.exe"
chrome_options = Options.Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(driver_xpath2 ,options=chrome_options )
driver.get("https://www.google.com")
print("yo ")
time.sleep(2)
def open_2_pages():
processes = []
for i in range(2):
open_a_page()
window=Tk()
B = Button(window, text ="go", command = open_2_pages) # when i click this button it opens 2 googles
B.place(x=10, y=10);
window.mainloop();
So the problem is the combination of both multiprocessing and chromedriver, but individually they're fine.
How can i use multiprocessed chromedrivers with tkinter without it opening new windows? why does this happen? why does everything work as intended running in pythons idle?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
