#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    3
    Rep Power
    0

    Multiple commands to a button?


    Does anyone know if there's a way to string multiple commands to a button?

    I have a small app that has a menu command to pull up a search entry in a new frame, with a close button... when You click on the search menu option, it deletes the search option (to keep from opening multiple frames), so I want to know if there's a way to get the close button (in the frame) to run multiple commands when clicked. I want it to insert the menu option for search again, and frame.destroy as well.

    I tried creating a function that would just do both, and tie the button to that, but for some reason (and I'm a serious newbie; about one week's worth of experience), I can't close the frame from within another function.

    Relevant code is below:
    Code:
    def insert():
        menu.delete(3) #deletes the menu option that called this function
        cframe = Frame(main)
        def search(event):
            ENTRY = entry.get()
            """Bunch of search stuff"""
    
        entry = Entry(cframe)
        entry.pack(side=TOP)
        entry.bind("<Return>", search)
        searchButton = Button(cframe, text='Search')
        searchButton.bind("<Button>", search)
        searchButton.pack(side=TOP)
    
        b1 = Button(cframe,text='Close',command=menu.insert_command(3, label="Search", command=insert),command=cframe.destroy).pack(side=TOP)
        cframe.pack(side=TOP)
    If you look, it's not hard to see how I'm trying to string multiple commands to the "b1" button, but I just don't know how to pull it off. Like I said, I tried to define another function, but in that function, cframe.destroy does absolutely nothing whatsoever. I don't get it. Any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Two things:

    a) What toolkit are you using?
    b) I think a better general feel for what you are trying to do with the whole app would be better
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    3
    Rep Power
    0
    Sorry, I'm using Tkinter for the GUI.

    As for what it does, long story short, it opens a comma delimited text file, parses out each field into parts, and returns the relevant ones to the user, with field 1 being searchable.

    It's not incredibly complicated, just my limited knowledge of the language won't allow me to progress beyond the stuck spot I'm in.

    -9mm-
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    I think basically what you need to do is simply create a function that calls both of those other functions and then hook that one in as the callback function (command=).
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    3
    Rep Power
    0
    I tried that, but for some reason, I can't destroy a frame from any function other than the one that I called it in, and I don't know why. I would think that cframe.destroy would destroy it no matter where it was called from, but apparently, that isn't the case.

    Is there something I'm missing in regards to that? Because frankly, that does seem the way to work it, it just won't allow me to close a frame outside of where I created it. :'(

    -9mm-
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Well, unless you pass a reference to cframe into the other function, there's no way it can know what it is... it's a scope issue.

IMN logo majestic logo threadwatch logo seochat tools logo