Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > tkFileDialog question

Reply
Thread Tools

tkFileDialog question

 
 
jaime.suarez@crossmatch.net
Guest
Posts: n/a
 
      05-12-2005
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()

 
Reply With Quote
 
 
 
 
James Stroud
Guest
Posts: n/a
 
      05-13-2005
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, 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/
 
Reply With Quote
 
 
 
 
James Stroud
Guest
Posts: n/a
 
      05-13-2005
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, 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/
 
Reply With Quote
 
jaime.suarez@crossmatch.net
Guest
Posts: n/a
 
      05-13-2005
James, thank you very much for your answer.
Jaime

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tkFileDialog Question garyr Python 0 03-16-2011 08:35 PM
tkFileDialog question Matt Mitchell Python 4 11-16-2009 06:30 PM
RE: tkFileDialog question Matt Mitchell Python 1 11-14-2009 02:33 AM
tkFileDialog, askopenfiles in v2.6 question fransstil Python 1 11-27-2008 12:09 AM
tkFileDialog without a parent window Stephen Boulet Python 2 07-20-2003 01:41 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57