Hi there.

Iim wanting a button pressed to do TWO commands .. one after another.

instead of my current code
musicbu = Button(root, text = 'Backup Music', width = 17, command = musicback1)

and musicback1 is a def (): with a complete and working script, i wondered if i could within that def make it link to a second command after the first had finished directly without having to "press" another button?
eg .. the last line might be
goto musicback2

and then i "def musicback2():" with whatever i like. So it is really just a single line if something like that is possible, i would like to know, i can't find too much in the example codes doing something like this

Thanks for your time

7 Years
Discussion Span
Last Post by shadwickman

goto musicback2

I was just talking with a co-worker yesterday about BASIC. He mentioned that people should learn it simply to demonstrate how NOT to write code... heh

Anyway, to call a function you would do this:

>>> def musicback2():
...     print 'Hey this is the music back 2 function'
>>> musicback2()
Hey this is the music back 2 function

You simply use the name of the function with parenthesis. If your function has any parameters, you'll need to make sure you add those in the parenthesis too.


Alternatively, if the musicback1 script is complete and working, what you could do (especially if musicback1 is used elsewhere in your app) is define another function which calls musicback1 and then does any other bits that you want.

Here's a little pseudo-code to demonstrate what I mean:

def musicback1():
    #musicback1 code here....

def othercommand():
    #call the musicback1 function...
    # now do whatever else you wanted to do....
    # call any other functions, or write more script below.

# updated button code calls othercommand instead of musicbu1.
musicbu = Button(root, text='Backup Music', width=17, command=othercommand)

Is that any help to you?


Both these ideas work and fit into my code, unfortunately i was trying to find a workaround for a previous issue that i just can't nail on the head and this didn't work :( Thanks for trying guys, your answers are right, just not for what i was trying.


Judging by your first post, when you said "link it to another ..." did you mean pass the values and variables from the first function to the second one?

If you specify what this "previous issue" is that you're trying to fix we can help you out better :P

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.