有人可以指出我的逻辑来弄清楚如何将我的所有按钮点击计入标签并更新该计数吗?这是我到目前为止所拥有的。在我的脑海里,我无法弄清楚如何在保持其他命令的同时告诉它我想要什么。这是我到目前为止的文字:
import sys
from tkinter import *
tP = 0
def mBall():
mtext = 'Ball'
mtext1 = 'Total Pitches: ' + str(int(tP + 1))
mlabel2 = Label(mGui, text = mtext).grid(sticky = W)
mlabel3 = Label(mGui, text = mtext1).grid(row = 5, column = 1, sticky = W)
def mStrike():
mtext = 'Strike'
mlabel2 = Label(mGui, text = mtext).grid(sticky = W)
def mFoul():
mtext = 'Foul'
mlabel2 = Label(mGui, text = mtext).grid(sticky = W)
def mInPlay():
mtext = '* ' + ment.get()
mtext1 = 'Total Pitches: 0'
mlabel2 = Label(mGui, text = mtext).grid(sticky = W)
mlabel3 = Label(mGui, text = mtext1).grid(row = 5, column = 1, sticky = W)
return tP = tP + 1
mGui = Tk()
ment = StringVar()
mGui.geometry('250x450+500+300')
mGui.title('My Copy')
mlabel = Label(mGui, text = 'Pitch Counter').grid(row = 0, column = 0, columnspan = 2, sticky = N)
mlabel = Label(mGui, text = 'r2').grid(row = 2, column = 1, columnspan = 2, sticky = N)
mlabel = Label(mGui, text = 'r4').grid(row = 4, column = 1, columnspan = 2, sticky = N)
mBall = Button(mGui, text = 'Ball', command = mBall, fg = 'white', bg = 'blue').grid(row = 1, column = 0, columnspan = 2, sticky = W)
mStrike = Button(mGui, text = 'Strike', command = mStrike, fg = 'white', bg = 'blue').grid(row = 1, column = 0, columnspan = 2, sticky = N)
mFoul = Button(mGui, text = 'Foul', command = mFoul, fg = 'white', bg = 'blue').grid(row = 1, column = 0, columnspan = 2, sticky = E)
mInPlay = Button(mGui, text = 'In Play', command = mInPlay, fg = 'white', bg = 'blue').grid(row = 3, column = 0, columnspan = 2, sticky = N)
mEntry = Entry(mGui, textvariable = ment).grid()