score:15
Make a new function that calls both:
def o_and_t():
o()
t()
button = Button(admin, text='Press', command=o_and_t)
Alternatively, you can use this fun little function:
def sequence(*functions):
def func(*args, **kwargs):
return_value = None
for function in functions:
return_value = function(*args, **kwargs)
return return_value
return func
Then you can use it like this:
button = Button(admin, text='Press', command=sequence(o, t))
score:-3
Correct me if I'm wrong, but whenever I needed a button to operate multiple functions, I would establish the button once:
button = Button(admin, text='Press', command=o)
And then add another function using the .configure()
:
button.configure(command=t)
Added to your script, it would look like this
from Tkinter import *
admin = Tk()
def o():
print '1'
def t():
print '2'
button = Button(admin, text='Press', command=o)
button.configure(command=t)
button.pack()
This could run multiple functions, well as a function and a admin.destroy
or any other command without using a global variable or having to redefine anything
score:2
The syntax you're trying for doesn't exist unfortunately. What you'd need to do is make a wrapper function that runs both of your functions. A lazy solution would be something like:
def multifunction(*args):
for function in args:
function(s)
cb = lambda: multifunction(o, t)
button = Button(admin, text='Press', command=cb)
score:16
you can use the sample way with lambda like this:
button = Button(text="press", command=lambda:[function1(), function2()])
Credit To: stackoverflow.com