擅长:python、mysql、java
<p>我认为问题是你的变量不是全局变量,你只在函数中声明变量。
请尝试使用以下代码:</p>
<pre><code>
startTime = 0
def start1():
global startTime
Canvas1 = Canvas(ReactionTest,width = 500,height = 450)
Canvas1.grid(row=4,column=0,columnspan=3,pady=10)
image_1 = PhotoImage(file="photo_1.gif")
Canvas1.create_image(0,0,anchor=NW, image=image_1)
Canvas1.image_1=image_1
startTime = time.strftime('%S')
def end1():
global startTime
endTime = time.strftime('%S')
calctimeTaken = int(endTime) - int(startTime)
timeTaken = str(calctimetaken)
</code></pre>