Home > other >  Python script not working when compiled with py2exe
Python script not working when compiled with py2exe

Time:01-26

I am new to Python and Tkinter. I have made a Tkinter Python Script which opens a URL in automated Chrome and does some clicking on pre-defined options. The script runs fine. But when I convert it into .exe using py2exe, following this tutorial

https://www.youtube.com/watch?v=UZX5kH72Yx4&ab_channel=TechWithTim

The .exe is made but when I open it, the GUI works fine but Chrome won't open and nothing happens from there.

Where am I going wrong? Thank you for valuable time and consideration.

This is how my GUI looks : GUI-preview

Here's my code :

from tkinter import *
from functools import partial

def validateLogin(username, password):
    print("username entered :", username.get())
    print("password entered :", password.get())
    user_name_aktu_prutor = username.get()
    password_aktu_prutor = password.get()


    import datetime  
    import time  
    import selenium  
    import re, regex  
    import os  
    import pyautogui  

    from selenium import webdriver
    import chromedriver_autoinstaller
    from selenium.webdriver.chrome.service import Service

    chromedriver_autoinstaller.install()
    driver = webdriver.Chrome(service=Service())


    url = "https://aktu.prutor.ai/"
    driver.get(url)
    time.sleep(3)

    driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div[2]/ul/li[1]/a').click()
    time.sleep(3)

    #   typing username
    driver.find_element_by_xpath('//*[@id="user_login"]').click()
    time.sleep(1)
    pyautogui.write(user_name_aktu_prutor) 
    time.sleep(2)

    #   typing password
    driver.find_element_by_xpath('//*[@id="user_pass"]').click()
    time.sleep(1)
    pyautogui.write(password_aktu_prutor)
    time.sleep(2)



    #   clicking login
    driver.find_element_by_xpath('//*[@id="wp-submit"]').click()
    time.sleep(5)

    #   clicking on profile
    driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div[2]/ul/li[1]/a/span').click()
    time.sleep(5)

    #   clicking on all my quizzes
    driver.find_element_by_xpath('//*[@id="post-24"]/div[2]/ul/li[3]/a').click()
    time.sleep(5)

    driver.close()

    return

#window
tkWindow = Tk()
tkWindow.geometry('550x180')
tkWindow.title('auto-AI')

#username label and text entry box
usernameLabel0 = Label(tkWindow, text="Automate your AKTU AI Quizzes!").grid(row=0, column=2)

usernameLabel = Label(tkWindow, text="User Name ([email protected])").grid(row=1, column=1)
username = StringVar()
usernameEntry = Entry(tkWindow, textvariable=username).grid(row=1, column=2)

#password label and password entry box
passwordLabel = Label(tkWindow,text="Password (at aktu.prutor)").grid(row=2, column=1)
password = StringVar()
passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=2, column=2)

validateLogin = partial(validateLogin, username, password)

#login button
loginButton = Button(tkWindow, text="Start", command=validateLogin).grid(row=6, column=2)
usernameLabel002 = Label(tkWindow, text="Make sure Caps Lock is switched OFF .").grid(row=7, column=2)
usernameLabel00 = Label(tkWindow, text="dont click or press anywhere while app is running").grid(row=8, column=2)
usernameLabel003 = Label(tkWindow, text="Version 1.0.0 Valid for Jan-Feb 2022").grid(row=9, column=2)
usernameLabel004 = Label(tkWindow, text="press alt ctrl del to terminate app while running").grid(row=9, column=2)


tkWindow.mainloop()

CodePudding user response:

Someone had a similar question. What I would suggest is try using pyinstaller and follow this thread. It seems they figured out how to make it work.

CodePudding user response:

This may not be an issue with your code. As @adenosinetp10 suggested, try using a different compiler. I would suggest auto-py-to-exe. It uses pyinstaller but gives a gui to make the process easier. Try this tutorial

  •  Tags:  
  • Related