我写了一个计数器,它的工作原理是不被其他函数识别。我想让这个计数器在任何其他功能中工作
def buttoncounter(self):
self.showthis = str([self.videofirstbutton.get(),
self.videosecondbutton.get(),
self.videothirdbutton.get(),
self.videofourthbutton.get(),
self.videofifthbutton.get(),
self.videosixthbutton.get(),
self.homevideofirstbutton.get(),
self.homevideosecondbutton.get(),
self.homevideothirdbutton.get(),
self.homevideofourthbutton.get(),
self.homevideofifthbutton.get(),
self.homevideosixthbutton.get(),
self.castingfirstbutton.get(),
self.castingsecondbutton.get(),
self.castingthirdbutton.get(),
self.castingfourthbutton.get(),
self.castingfifthbutton.get(),
self.castingsixthbutton.get()])
self.counter = print(self.showthis.count('1'))
def printbutton(self):
self.printbutton = Button(self.frame, text="Print Events " + str(self.counter), width=15, command=self.buttoncounter) #str(self.counter)
self.printbutton.pack( side = LEFT )
错误是:
line 211, in printbutton
self.printbutton = Button(self.frame, text="Print Events " + str(self.counter), width=15, command=self.buttoncounter) #str(self.counter)
AttributeError: 'App' object has no attribute 'counter'
我希望按钮的输出是“Print Events(myanswer)”,但它只是一起拒绝了它
我不知道该把这个放哪儿
相应地调整打印事件
正如@Paul Rooney在评论中解释的那样,错误的一行是
self.counter = print(self.showthis.count('1'))
。print
函数接受字符串作为输入,并将它们写入stdout。顺便说一句,在Python中,所有不返回任何内容的函数实际上都返回None
。因此,如果您决定存储一个不返回任何内容的函数的输出,您将得到None
:相关问题 更多 >
编程相关推荐