I am using Tkinter and trying to call a function within a class, but not getting it to work properly.
class Access_all_elements:
def refSelect_load_file(self):
self.reffname = askopenfilename(filetypes=(("XML files", "*.xml"),
("All files", "*.*") ))
if self.reffname:
fileOpen = open(self.reffname)
refSelect = Button(topFrame, text="Open Reference File",
command=lambda:refSelect_load_file(self), bg = "yellow")
refSelect.grid(row =1, column=1)
Error:
On executing above command, on pressing the button I get following error:
NameError: global name 'refSelect_load_file' is not defined
What I tried:
I tried calling a function using tkinter's generic approach which is not working for me.
refSelect = Button(topFrame, text="Open Reference File",
command=refSelect_load_file, bg = "yellow")
refSelect.grid(row =1, column=1)
This throws me error:
TypeError: refSelect_load_file() takes exactly 1 argument (0 given)
Can you guys suggest me something here?
__init__. If you were in a method, you could docommand=self.refSelect_load_file._init_refSelect_load_file(lowercase leading "r") but the error message showsRefSelect_load_file(uppercase leading "r")