September 11th, 2003, 08:10 PM
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:
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?
menu.delete(3) #deletes the menu option that called this function
cframe = Frame(main)
ENTRY = entry.get()
"""Bunch of search stuff"""
entry = Entry(cframe)
searchButton = Button(cframe, text='Search')
b1 = Button(cframe,text='Close',command=menu.insert_command(3, label="Search", command=insert),command=cframe.destroy).pack(side=TOP)
September 12th, 2003, 04:11 PM
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
September 13th, 2003, 03:26 PM
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.
September 13th, 2003, 06:21 PM
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=).
September 13th, 2003, 06:36 PM
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. :'(
September 14th, 2003, 03:03 AM
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.