tkFileDialog question

Discussion in 'Python' started by jaime.suarez@crossmatch.net, May 12, 2005.

  1. Guest

    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()
     
    , May 12, 2005
    #1
    1. Advertising

  2. James Stroud Guest

    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/
     
    James Stroud, May 13, 2005
    #2
    1. Advertising

  3. James Stroud Guest

    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/
     
    James Stroud, May 13, 2005
    #3
  4. Guest

    James, thank you very much for your answer.
    Jaime
     
    , May 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Boulet

    tkFileDialog without a parent window

    Stephen Boulet, Jul 3, 2003, in forum: Python
    Replies:
    2
    Views:
    505
    klappnase
    Jul 20, 2003
  2. fransstil
    Replies:
    1
    Views:
    583
  3. Matt Mitchell

    tkFileDialog question

    Matt Mitchell, Nov 13, 2009, in forum: Python
    Replies:
    4
    Views:
    374
    Matt Mitchell
    Nov 16, 2009
  4. Matt Mitchell

    RE: tkFileDialog question

    Matt Mitchell, Nov 13, 2009, in forum: Python
    Replies:
    1
    Views:
    484
  5. garyr

    tkFileDialog Question

    garyr, Mar 16, 2011, in forum: Python
    Replies:
    0
    Views:
    247
    garyr
    Mar 16, 2011
Loading...

Share This Page