0
我目前正在使用下面的代碼,但每次嘗試點擊calcButt按鈕時,它都不會執行任何操作。什麼似乎是問題 - 我做錯了什麼? 我一個月前纔開始編碼python,所以我對這個很新。 我希望你們能幫助我:)PyCharm不打印結果
from tkinter import *
import Calculations
root = Tk()
# ***** function - is in an imported document *****
def calc_kJ(Protein, Carbs, Fat):
protein = Protein * 17
carbs = Carbs * 17
fat = Fat * 37
return protein + carbs + fat
# ***** Labels and inputs *****
proteinLabel = Label(root, text="Protein in gram:")
carbsLabel = Label(root, text="Carbs in gram:")
fatLabel = Label(root, text="Fat in gram:")
proteinInput = Entry(root)
carbsInput = Entry(root)
fatInput = Entry(root)
calcButt = Button(text="Calculate amount of kJ", command=Calculations.calc_kJ(Protein=proteinInput.get(), Carbs=carbsInput.get(), Fat=fatInput.get()))
# ***** Grid layout *****
proteinLabel.grid(row=0, sticky=W)
carbsLabel.grid(row=1, sticky=W)
fatLabel.grid(row=2, sticky=W)
proteinInput.grid(row=0,column=1)
carbsInput.grid(row=1, column=1)
fatInput.grid(row=2, column=1)
calcButt.grid(row=3, columnspan=2)
root.mainloop()
非常感謝你的確。如前所述,我剛剛剛剛開始編程,所以我很新。但代碼現在按預期工作! :) – 2014-09-29 18:25:44