多流行的Chromedrivers导致我的TKINTER程序的构建打开额外的TKINTER WINDOWS

发布于 2025-01-23 08:25:45 字数 3167 浏览 2 评论 0原文

我有一个非常基本的TKINTER程序(基本上我希望能够在单击按钮时运行一些截然不同的多型铬源。)这一切都可以在空闲中效果很好,但是当我使用cx_freeze来使构建构建时,它的行为方式有所不同。

当我单击“构建版本”时,它将打开一个全新的TKINTER窗口,还可以运行Chromedriver功能。当我以CMD线而不是空闲状态运行程序时,这也会发生。但是,一切都很好,它只是在不打开新窗口的情况下运行功能。

脚本

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

我希望我的构建 /命令行,就像在空闲中一样工作。我在这里做错了什么?

更新

我试图通过从方程式中删除Chrome驱动程序来进一步简化问题,但是这解决了问题。因此,我认为ChromeDriver应该归咎于。

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

如何使我的原始程序与多型发datched Chromedrivers一起使用,而无需打开其他TKINTER WINDOWS?

更新2

我已删除了多次措施,但留在Chromedriver中,这也解决了问题。

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

因此,问题是多处理和Chromedriver的组合,但单独使用它们。

如何在不打开新窗口的情况下将多处理的Chromedrivers与TKINTER一起使用?为什么会发生这种情况? 为什么一切都按照蟒蛇闲置的意图运行?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文