我试图reset
从当前类外部调用该函数(这最终将在多个类上调用重置)但我得到的是似乎再次运行整个类的程序,而不仅仅是该类中的函数。
到底是怎么回事?
from tkinter import *
root = Tk()
class Scores1(Frame):
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
self.team1 = 888
self.team1str = StringVar()
self.teamA()
def teamA(self):
self.team1str.set('%03d' % (self.team1))
t1 = Label(textvariable=self.team1str, font=("Digiface", 120), fg='#fffd80000', bg='black')
t1.grid()
def ScoreA1(self):
self.team1 = self.team1 + 1
self.team1str.set('%03d' % (self.team1))
def Reset(self):
self.team1 = 0
self.team1str.set('%03d' % (self.team1))
class Resetter(Frame):
def __init__(self, parent=None, **kw):
Frame.__init__(self, parent, kw)
def reset(self):
Scores1().Reset
def main():
sc1 = Scores1(root)
sc1.grid(row=0, column=0)
res = Resetter(root)
sc1.configure(highlightbackground='white', highlightthickness=2)
root.configure(background = 'black')
Button(root, text='Team A +1', command=sc1.ScoreA1).grid(row=1, column=0)
Button(root, text='ResetInside', command=sc1.Reset).grid(row=2, column=0)
Button(root, text='ResetOutside', command=res.reset).grid(row=3, column=0)
root.mainloop()
if __name__ == '__main__':
main()