469,323 Members | 1,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

tkFileDialog question

I am creating a very simple GUI with one Entry widget and
one Button. The purpose of the Button widget is to Browse for
a file using tkFileDialog.askopenfilename().

I bind the button to a handler which spawns a tkFileDialog. This
works but the button __stays depressed__ after the handler returns!
Any ideas why?

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0 columnspan=2)

self.button1 = Button(self.myContainer1)
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("<Button-1>", self.button1Click)
self.button1.bind("<Return>", self.button1Click)
def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()

Jul 19 '05 #1
3 1474
I think you are better off not binding a button like you are doing.
Use the "command" option to get the behavior you want. E.g:

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0, columnspan=2)
self.button1 = Button(self.myContainer1,
command=(lambda: self.button1Click(self)))
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("<Return>", self.button1Click)

def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()
James

On Thursday 12 May 2005 03:43 pm, ja**********@crossmatch.net wrote:
I am creating a very simple GUI with one Entry widget and
one Button. The purpose of the Button widget is to Browse for
a file using tkFileDialog.askopenfilename().

I bind the button to a handler which spawns a tkFileDialog. This
works but the button __stays depressed__ after the handler returns!
Any ideas why?

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0 columnspan=2)

self.button1 = Button(self.myContainer1)
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("<Button-1>", self.button1Click)
self.button1.bind("<Return>", self.button1Click)
def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jul 19 '05 #2
Oops,

That should have been,
class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0, columnspan=2)
self.button1 = Button(self.myContainer1,
command=(lambda: self.button1Click()))
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("<Return>", self.button1Click)

def button1Click(self, event=None):
filePick = tkFileDialog.askopenfilename()
On Thursday 12 May 2005 03:43 pm, ja**********@crossmatch.net wrote:
I am creating a very simple GUI with one Entry widget and
one Button. The purpose of the Button widget is to Browse for
a file using tkFileDialog.askopenfilename().

I bind the button to a handler which spawns a tkFileDialog. This
works but the button __stays depressed__ after the handler returns!
Any ideas why?

class MyApp:
def __init__(self, parent):
self.myParent = parent
self.myContainer1 = Frame(parent)
self.myContainer1.pack()

self.entry = Entry(self.myContainer1)
self.entry.grid(row=0,column=0 columnspan=2)

self.button1 = Button(self.myContainer1)
self.button1.configure(text="...")
self.button1.grid(row=0, column=2)
self.button1.bind("<Button-1>", self.button1Click)
self.button1.bind("<Return>", self.button1Click)
def button1Click(self, event):
filePick = tkFileDialog.askopenfilename()


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jul 19 '05 #3
James, thank you very much for your answer.
Jaime

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tim Williams | last post: by
reply views Thread by Matthias Huening | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.