以下是相关代码:
from Tkinter import *
import time
class Application(Frame):
"""Jungle Timers"""
def __init__(self, master):
"""Initialize the Frame."""
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
"""Buttons for timer."""
#create buttons
self.b1 = Button(self, text = "Own Blue Up In: 0", command = self.b1)
self.b1.grid()
self.r1 = Button(self, text = "Own Red Up In: 0", command = self.r1)
self.r1.grid()
self.b2 = Button(self, text = "Their Blue Up In: 0", command = self.b2)
self.b2.grid()
self.r2 = Button(self, text = "Their Red Up In: 0", command = self.r2)
self.r2.grid()
self.d = Button(self, text = "Dragon Up In: 0", command = self.d)
self.d.grid()
self.baron = Button(self, text = "Baron Up In: 0", command = self.baron)
self.baron.grid()
def b1(self):
x = 300
while x > 0:
self.b1(text = "Own Blue Up In: " + str(x))
x -= 1
time.sleep(1)
def r1(self):
x = 300
while x > 0:
self.r1(text = "Own Red Up In: " + str(x))
x -= 1
time.sleep(1)
def b2(self):
x = 300
while x > 0:
self.b2(text = "Their Blue Up In: " + str(x))
x -= 1
time.sleep(1)
def r2(self):
x = 300
while x > 0:
self.r2(text = "Their Red Up In: " + str(x))
x -= 1
time.sleep(1)
def d(self):
x = 360
while x > 0:
self.d(text = "Dragon Up In: " + str(x))
x -= 1
time.sleep(1)
def baron(self):
x = 420
while x > 0:
self.baron(text = "Baron Up In: " + str(x))
x -= 1
time.sleep(1)
root = Tk()
root.title("Jungle Timers")
root.geometry("200x210")
app = Application(root)
root.mainloop()
使用此代码我得到了AttributeError:第37行的Button实例没有调用方法。
self.b1(text = "Own Blue Up In: " + str(x))
我这样做是完全错误还是有一种简单的方法可以解决这个问题?任何帮助将不胜感激。
答案 0 :(得分:0)
应该是:
self.b1.config(text = "Own Blue Up In: " + str(x))