Hello everyone I am new to python, I hope you can help me, the problem I have is the following.
I have a form (tkinter) .pyw where I collect some data and I intend to take them to an independent function that runs in parallel from a py.
I'm trying to pass the data through a function using a list but the data does not arrive ... I'll explain it better with code and I hope you can guide me on this thanks ...
in the code I have placed > > > STEPS < < < < > to show the execution flow
steps 1, 2, 4, 5 are executed in function 1 (.py file) and step 3 is executed in function 2 (.pyw file)
function 1 name file functions.py
class FunctionsClass():
#esta variable la declaro aca fuera de cualquier funcion directo al inicio de la clase con el objetivo de que sea accesible desde
#cualquier función y con la esperanza de que
# al modificar su valor con la funcion "ModNames()" los valores se mantengan en memoria pero eso no ocurre
_PDFdatos=[]
#esta funcion "ModNames()" tine como objetivo ser llamada desde el form en tkinter y modificar "_PDFdatos"
# con esperando que el valor se mantenga en memoria >>> LO QUE NO OCURRE <<<
def ModNames(self,PDFuserName,PDFuserLast,PDFuserNum,PDFfileType):
#limpueza de variales
self._PDFdatos.clear()
#>>>PASO 4<<< quepa destacar que si coloco un print aca me
# muestra los datos que estoy enviando desde la app desde la
# funcion return_entry()
self._PDFdatos=[PDFuserName, PDFuserLast, PDFuserNum, PDFfileType]
return self._PDFdatos
def GETdatos(self):
return self._PDFdatos
def GetName(self):
#las variables abajo cargan direcciones desde un archivo
_Instdir=sysVar.VarInstalationDir()
_dirPDF=sysVar.VarDirPDF()
ldir="{}{}".format(_Instdir,"/AppGetName")
os.chdir(ldir)
#ojo aca llamo al formulario tkinter para cargar los datos
comando="{}".format("\"python RootForm.pyw\"")
#>>>PASO 2<<< se ejecuta la app grafica
os.system(comando)
os.chdir(_dirPDF)
def CambiarNombrePDF(self,_dirPDF,_convert2PDF)
#>>>PASO 1<<< se llama a la funcion GetName()
self.GetName()
# >>>PASO 5<<< LUEGO en este punto donde supongo debería tener
# los valores en _PDFdatos dado que uso self.GETdatos() y me deberia
# retornar la misma lista que acabo de modificar pero no funciona
# ojo escribi la funcion self.GETdatos() como para probar una
# alternativa ya que en un principio simplemente utilice
# _PDFuserName=self._PDFdatos[0] y tampoco funciono
_PDFdatos=self.GETdatos()
_PDFuserName=_PDFdatos[0]
_PDFuserLast=_PDFdatos[1]
_PDFuserNum=_PDFdatos[2]
_PDFfileType=_PDFdatos[3]
function 2 file named RootForm.pyw
this app is called from the "GetName ()" function in the functions.py file and additionally imports the functions.py in order to use the ModNames () function to return the values:
from functions import *
Job=FunctionsClass()
class AppGUI(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
#funcion que se utiliza para devolver los datos a la funcion objetivo
#llamando a ModNames() que fue declarada en FunctionsClass.py
def return_entry():
PDFuserName=_PDFuserName.get()
PDFuserLast=_PDFuserLast.get()
PDFuserNum=_PDFuserNum.get()
PDFfileType=_PDFfileType.get()
#>>>PASO 3<<< SE ENVIAN LOS DATOS
Job.ModNames(PDFuserName,PDFuserLast,PDFuserNum,PDFfileType)
self.master.destroy()
Label(Frame1, text="Enter customer's Name: ").grid(row=1, column=1, sticky=W)
_PDFuserName=StringVar()
Entry(Frame1, textvariable = _PDFuserName).grid(row=1, column=200, sticky=W)
Label(Frame1, text="Enter customer's Last Name: ").grid(row=2, column=1, rowspan = 1, columnspan = 6, sticky=W)
_PDFuserLast=StringVar()
Entry(Frame1, textvariable = _PDFuserLast).grid(row=2, column=200, sticky=W)
Label(Frame1, text="Enter customer's Last 4 SSN: ").grid(row=3, column=1, rowspan = 1, columnspan = 6, sticky=W)
_PDFuserNum=StringVar()
Entry(Frame1, textvariable = _PDFuserNum).grid(row=3, column=200, sticky=W)
Label(Frame1, text="Enter Document Type: ").grid(row=4, column=1, rowspan = 1, columnspan = 6, sticky=W)
_PDFfileType=StringVar()
Entry(Frame1, textvariable = _PDFfileType).grid(row=4, column=200, sticky=W)
Button(Frame2, text="ACCEPT",command=return_entry).grid(row=6,column=3,sticky=E+W)
self.master.mainloop()
root = Tk()
app = AppGUI(master=root)
Actualization 1 ., I put the comment that I deleted on the recommendation of the moderators, so that other readers can follow the thread: thank you very much Abulafiabpor your interest, as I had said before, it is true what you raise from the memory and I realized when I started to check the memory I'd of the variable id (self._PDFdatos) when accessing said variable from the app to modify it and check id in effect was different from when I opened it from it's script.
When I realized this, I started to integrate both the .pyw and the .py files and now I call the graphic app directly from the original script, which theoretically prevents me from running two different processes so that they now have () it does not make any sense since they are part of the code inserted in it. I wanted to discard the writing of data on disk since this process must check the folder every 5 seconds that brings a lot of wear to the client's disk, you think Is there a way to pass the data from the graphic app to the code or my only option is to finally write them to the disk? Thanks !!
Update 2 I'm going to try what you think of the return, since the other option or answers that you suggest does not apply to me much since in fact I am capturing the data that the user enters and uses the _PDFfileType = StringVar () from the beginning and with the get () if I see the data I can even manipulate them, but only on the side of the app (given that you mention that the app class created its own instance and its own variable ...
I'll let you know how it goes ..., thanks
Update 3
Hello FJSevilla , the procedures I did not understand are:
if __name__ == "__main__":
inst = FunctionsClass()
inst.cambiar_nombre_pdf(None, None)
and this one:
def __init__(self, master=None):
Frame.__init__(self, master)
However, reading your answer extensively, I got the link that you passed to me about the difference between attributes of instances and class attributes, so I think that's where I'm going to continue researching. once again thank you ...:)