1

How to run two commands on click on one button ?

Example:

def commend1():
  print "hi"

def commend2():
  print "hello"

#TKinter
button = Button(root, commend= ?)

I want them to run at the same time

Community
  • 1
  • 1
pro
  • 21
  • 1

2 Answers2

3

The most basic answer for that would be:

def commend1():
  print "hi"

def commend2():
  print "hello"

def cmd12():
  commend1()
  commend2()

#TKinter
button = Button(root, command=cmd12)
einsweniger
  • 611
  • 6
  • 16
1

You can have your commend1() to call commend2() like this :

def commend1():
  print "hi"
  commend2()

def commend2():
  print "hello"

#TKinter
button = Button(root, command= commend1)
manjy
  • 109
  • 1
  • 2
  • 12
  • Or you can try einsweniger's answer too – manjy Sep 20 '18 at 09:02
  • Do not work at the same time (run commend1 then commend2) , I want to work at the same time – pro Sep 20 '18 at 10:59
  • https://stackoverflow.com/questions/7207309/python-how-can-i-run-python-functions-in-parallel Check out this question. It may solve your query – manjy Sep 20 '18 at 11:49