-1
我正在编写代码以通过单击按钮将两个变量传递给函数。问题是在按下按钮之前它是这样做的。我究竟做错了什么?python按钮命令在点击前执行
calcButton = Button(window, text="Calculate Weight",
command=window.calc(5,10))
calcButton.place(x=225, y=85)
answertextLabel = Label(window, text="Answer:")
answertextLabel.place(x=225, y=65)
answerLabel = Label(window, text=answervar)
answerLabel.place(x=275, y=65)
def calc(window, diameter, density):
math = diameter + density
print (math)
谢谢。这工作,现在我开始明白为什么。当我能够时,我会接受答案! –