Когда я запускаю gui.py, я вижу кнопку, нажимаю ее, вижу появление окна Chrome и скрипт, работающий в окне Chrome. Когда я создаю .exe с помощью pyinstaller --onefile gui.py, графический интерфейс с кнопкой отображается правильно, но я больше не вижу окна Chrome.
Здесь код моего gui.py:
Код: Выделить всё
import sys
import os
import tkinter as tk
from tkinter import messagebox, filedialog
import subprocess
import shutil
def run_script():
try:
# I used it to troubleshooting the correct path to the script.py file
if hasattr(sys, '_MEIPASS'):
script_path = os.path.join(sys._MEIPASS, "script.py")
else:
script_path = os.path.join(os.path.dirname(__file__), "script.py")
result = subprocess.run([sys.executable, script_path], capture_output=True, text=True)
if result.returncode == 0:
messagebox.showinfo("Success", "Script ran successfully!")
print("Script ran successfully!")
print(result.stdout)
else:
error_message = f"Script failed with return code {result.returncode}:\n{result.stderr}"
messagebox.showerror("Error", error_message)
print(error_message)
except Exception as e:
error_message = f"An unexpected error occurred:\n{e}"
messagebox.showerror("Error", error_message)
print(error_message)
root = tk.Tk()
root.title("Run Script and Upload CSV")
run_button = tk.Button(root, text="Run Script", command=run_script)
run_button.pack(pady=10)
root.mainloop()
Код: Выделить всё
import os
import pandas as pd
from selenium.common import TimeoutException, NoSuchElementException, ElementClickInterceptedException
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# I need this dataframe for working in as many chrome windows as many rows I have. Ignore it if you do not find it relevant
df = pd.read_csv('list.csv')
df.cp = df.cp.astype(str)
service = Service()
website = 'https://google.com'
for i, j in df.iterrows():
driver = webdriver.Chrome(service=service)
driver.get(website)
time.sleep(3) #....the rest of the code...
Подробнее здесь: https://stackoverflow.com/questions/786 ... h-selenium