DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
SiawaschAmootari
SiawaschAmootari

Posted on

Python script works in VSC but not as exe

I have a problem with the current project I am working on. When I start my script in VSC then everything works fine and currently works as it is intended. I converted the whole thing as an exe with auto-py-to-exe and that also worked normally ... except that the first script has not called the second although the first has recognized that in the folder a new XML file exists. I thought first the error lies with auto-py-to-exe but then I started the scripts manually and there it was exactly the same so auto-py-to-exe has made no error in any case, if I start the scripts manually (so in which I click on the .py file) then it also does not work as wanted it happens exactly the same as with the exe file. My goal is that the exe file works the same way as the whole thing in VSC.

import os, time
import TestGui
def main():
    print("in Watchdog")
    path_to_watch = "................"

    before = dict ([(f, None) for f in os.listdir (path_to_watch)])
    done = True
    while done:
        time.sleep (10)
        after = dict ([(f, None) for f in os.listdir (path_to_watch)])
        added = [f for f in after if not f in before]
        removed = [f for f in before if not f in after]
        if added: print ("Added: ", ", ".join (added)) 
        if removed: print ("Removed: ", ", ".join (removed))


        print(type(added))

        if len(added)>0:
            if ".xml" in added[-1]:
                print("iΒ΄m in")
                TestGui.start_app(added)  

                   # before = dict ([(f, None) for f in os.listdir (path_to_watch)])
                   # done = False
                   # exit()
if __name__ == "__main__":
    main() 

Enter fullscreen mode Exit fullscreen mode

here the GUI

import tkinter as tk
from tkinter import Label, filedialog , Text
import os
import xml.etree.ElementTree as ET
from PIL import Image, ImageTk


def start_app(added):

        root = tk.Tk()

        root.configure(background='white')


        report_file = open(added[-1], 'r', encoding= "cp1252") 

        xml_file =[]
        error_bool = False
        for line in report_file:
            stripped_line = line.strip()
            #line_list = stripped_line.split()
            xml_file.append(stripped_line)

        report_file.close()
        errorList =[]
        operationList =[]
        counterList =[]
        for line in xml_file:
            if "description='"" in line:
                line = line.split(""")
                operationList.append(line[1])

        for line in xml_file:
            if line.find("simulator_out_of_range") == 1 or line.find("simulator_collision") ==1 or line.find("operation id=")==1:
                if "operation id=" in line :
                    line = line.split('"')
                    counterList.append(line[1])

                    errorList.append(operationList[int(line[1])-1])

                elif not (len(errorList)>1 and line == errorList[-1]):
                    errorList.append(line)
                    error_bool = True


        t = Text(root, width = 100, height = 10, wrap = "none", background= "white", foreground="black")
        ys = tk.Scrollbar(root, orient = 'vertical', command = t.yview)
        xs = tk.Scrollbar(root, orient = 'horizontal', command = t.xview)
        t['yscrollcommand'] = ys.set
        t['xscrollcommand'] = xs.set
        for line in errorList:
            t.insert('end', line+"\n")
        t.grid(column = 0, row = 0, sticky = 'nwes')
        xs.grid(column = 0, row = 1, sticky = 'we')
        ys.grid(column = 1, row = 0, sticky = 'ns')

        if error_bool is True:
            img = Image.open('thumbs_down.png')
        else: 
            img = Image.open('thumbs_up.png')

        img = ImageTk.PhotoImage(img)
        img_label = tk.Label(image=img)
        img_label.image = img
        img_label.grid(column=3,row=0)

        close_btn_text = tk.StringVar()
        close_btn = tk.Button(root, textvariable= close_btn_text, font="Raleway", command= lambda:[exit()])
        close_btn_text.set("Close Report")
        close_btn.grid(column=1, row=2)
        #root.grid_columnconfigure(0, weight = 1)
        #root.grid_rowconfigure(0, weight = 1)


        root.mainloop()


Enter fullscreen mode Exit fullscreen mode

Hope someone can help me

Top comments (0)

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›