尝试制作一个简单的GUI应用程序,该应用程序只有3个标签,每个标签有2个按钮,用于递增和递减数字。不知道问题是否出在多个标签上,我使用单个标签是否成功。
import tkinter as tkinter
import sys
root = tkinter.Tk()
root.title("Desperation")
winCounter = tkinter.IntVar()
tieCounter = tkinter.IntVar()
loseCounter = tkinter.IntVar()
def countUp(counter):
counter.set(counter.get() + 1)
def countDown(counter):
counter.set(counter.get() - 1)
def countClear(event=None):
winCounter.set(0)
loseCounter.set(0)
tieCounter.set(0)
tkinter.Label(root, textvariable=winCounter, fg = "white", bg ="green", font = "Verdana 10 bold").pack()
tkinter.Label(root, textvariable=tieCounter, fg = "white", bg ="green", font = "Verdana 10 bold").pack()
tkinter.Label(root, textvariable=loseCounter, fg = "white", bg ="green", font = "Verdana 10 bold").pack()
tkinter.Button(root, text="Win +1", command=countUp(winCounter)).pack()
tkinter.Button(root, text="Win -1", command=countDown(winCounter)).pack()
tkinter.Button(root, text="Lose +1", command=countUp(loseCounter)).pack()
tkinter.Button(root, text="Lose -1", command=countDown(loseCounter)).pack()
tkinter.Button(root, text="Tie +1", command=countUp(tieCounter)).pack()
tkinter.Button(root, text="Tie -1", command=countDown(tieCounter)).pack()
tkinter.Button(root, text="CLEAR!!", command=countClear).pack()
root.mainloop()
谢谢!