I have a class as given below and I want to access some of variables located inside function of that class. The structure is as below:
class access_all_elements:
def RefSelect_load_file():
reffname = askopenfilename(filetypes=(("XML files", "*.xml"),
("All files", "*.*") ))
if reffname:
ReferenceXML.insert(END,fileOpen.read())
recovering_parser = etree.XMLParser(recover=True)
AdasReference = etree.parse(reffname, parser=recovering_parser).getroot()
AdasReferenceString = etree.fromstring(ToStringAdasReference)
TimeReferenceTest = AdasReferenceString.findall("{http://www.google.com/car}bmw")
return TimeReferenceTest
def CopySelect_load_file():
#same code as above, but for loading another file in same GUI
Description of code
1). class access_all_elements:
class to access all elements inside
2). def RefSelect_load_file():
function inside class that loads xml file
3). ReferenceXML.insert(END,fileOpen.read())
insert filepath in text box inside gui
4). AdasReference:
Parse xml file located in reffname
5). TimeReferenceTest:
this extracts all the elements from xml having label car
The output of this variable looks like: [<Element {http://www.google.com/car}bmw at 0x279ff08>, <Element {http://www.google.com/car}bmw at 0x279ffa8>.....]
5). return TimeReferenceTest
I want to return the value of this variable when function is called
What I want:
There is another function outside this class namely callback
which uses one of the variable which is located in access_all_elements
class and that variable is TimeReferenceTest
. I want to access the value of this variable in the below given function. The value is mentioned in 5th
point above. The function outside class looks like below:
def callback():
toplevel = Tk()
toplevel.title('Another window')
RWidth=Root.winfo_screenwidth()
RHeight=Root.winfo_screenheight()
toplevel.geometry(("%dx%d")%(RWidth,RHeight))
for i,j in zip(TimeReferenceTest,TimeCopyTest): #TimeCopyTest is also like TimeReferenceTest defined in above class under CopySelect_load_file() function,but not mentioned here
.......
To put it simply, out of entire entity of RefSelect_load_file()
function I only want to access the value of variable TimeReferenceTest
in line for i,j in zip(TimeReferenceTest,TimeCopyTest)
when callback
is function is executed
What I tried and What this is all about
First all, I am making a GUI in Tkinter and trying to bind all the code I wrote with that gui. Callback
is invoked when someone presses button to compare two xml files.
What I tried so far is the approach of encapsulating both functions into same class as shown above to access its variables. I call the class in following manner:
c = access_all_elements()
c.RefSelect_load_file()
The problem here is I know this function is defined in a way to open file dialogue box, but I want to return value of only TimeReferenceTest
when I call it in callback
function. So is there any way you can suggest where i can access that variable without executing entire function?