python tkinter,如何在单击一个按钮时运行两个命令?

时间:2018-09-20 08:53:29

标签: python python-2.7 tkinter

如何在单击一个按钮时运行两个命令?

示例:

def commend1():
  print "hi"

def commend2():
  print "hello"

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

我希望它们同时运行

2 个答案:

答案 0 :(得分:2)

最基本的答案是:

def commend1():
  print "hi"

def commend2():
  print "hello"

def cmd12():
  commend1()
  commend2()

#TKinter
button = Button(root, command=cmd12)

答案 1 :(得分:0)

您可以像这样通过commend1()调用commend2():

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

def commend2():
  print "hello"

#TKinter
button = Button(root, command= commend1)