【发布时间】:2016-08-12 00:17:34
【问题描述】:
当我尝试运行我的代码时遇到此错误:
File "./countdown.py", line 36, in <module>
app = Application(root)
File "./countdown.py", line 16, in __init__
self.create_buttons(self)
TypeError: create_buttons() takes exactly 1 argument (2 given)
这是我的代码:
import Tkinter as tk
class Application(tk.Frame):
"""Countdown app - simple timer"""
def __init__(self, master):
"""initialize frame"""
tk.Frame.__init__(self, master)
#super(Application, self).__init__(master)
self.grid()
self.create_buttons(self)
def create_buttons(self):
self.startBttn = Button(app, text = "Start")
self.startBttn.grid()
self.stopBttn = Button(app, text = "Stop")
self.stopBttn.grid()
self.resetBttn = Button(app, text = "Reset")
self.resetBttn.grid()
### Main Code ###
# create the root window using Tk - an object of tkinter class
root = tk.Tk()
# modify the prog. window (set size, title, etc.)
root.title("Countdown")
root.geometry("200x100")
#instantiate Application
app = Application(root)
我一直在寻找这个问题的答案,但无法将其他人的解决方案应用于我的代码 - 有什么想法吗?如果我删除 tk.在类 Application 声明中的 Frame 之前,我收到一个错误,提示找不到 Frame。如果我使用 super(Application, self).__init__(master) 而不是它上面的行,我会得到一个类型错误必须是类而不是类对象。
【问题讨论】: