Tkinter button command activates upon running program? Tkinter button command activates upon running program? tkinter tkinter

Tkinter button command activates upon running program?


Make your event handler a lambda function, which calls your get_dir() with whatever arguments you want:

xbBrowse = Button(frameN, text="Browse...", font=fontReg, command=lambda : self.get_dir(xbPath))


In the above code:

xbBrowse = Button(frameN,text="Browse...",font=fontReg,command=self.get_dir(xbPath))

You are invoking the function already, you should be simply passing the function:

xbBrowse = Button(frameN,text="Browse...",font=fontReg,command=self.get_dir)


You need to pass a reference of your get_dir method

so change

xbBrowse = Button(frameN,text="Browse...",font=fontReg,command=self.get_dir(xbPath))

to

xbBrowse = Button(frameN,text="Browse...",font=fontReg, command=self.get_dir)

Then make your Entry widget an instance variable so that you can access it in your get_dir method.

e.g.

self.xbPath = Entry(frameN,width=30,font=fontReg)

Then your get_dir() method will look like:

def get_dir(self):    tmp = askdirectory(mustexist=1,title="Please select a destination")    tmp = tmp.replace("/","\\")    self.xbPath.delete(0,END)    self.xbPath.insert(0,tmp)