__init__() missing 2 required positional arguments
请帮帮我。在这个创建按钮的简单tkinter程序中,我已经提供了所有三个参数,但是关于位置参数的错误将出现在屏幕上。抱歉我的英语不好。
1 2 3 4 5 6 7 8 9 10 11 | from tkinter import * class Button: def __init__(self, row, column, frame): self.row = row self.column = column b = Button(frame).grid(row = self.row, column = self.column) tk = Tk() b1 = Button(row = 1, column = 1, frame = tk) tk.mainloop() |
错误:
RESTART: C:\Users\vnira\Documents\python.projects\Flappy Bird\whiteboard.py
Traceback (most recent call last):
File"C:\Users\vnira\Documents\python.projects\Flappy Bird\whiteboard.py", line 11, in
b1 = Button(row = 1, column = 1, frame = tk)
File"C:\Users\vnira\Documents\python.projects\Flappy Bird\whiteboard.py", line 7, in init
Button(frame).grid(row = self.row, column = self.column)
TypeError: init() missing 2 required positional arguments: 'column' and 'frame'
提前谢谢
1 2 3 4 5 6 7 8 9 10 11 | from tkinter import * class Buttons: def __init__(self, row, column, frame): self.row = row self.column = column b = Button(frame).grid(row = self.row, column = self.column) tk = Tk() b1 = Buttons(row = 1, column = 1, frame = tk) tk.mainloop() |
当tkinter有class按钮时,您创建了一个class按钮。使用您自己的变量名可能会有所帮助:)我认为它试图递归地生成您创建的button类的实例,而不是生成tkinter模块内的button类的实例。
在
1 | b = Button(frame) |
由于
编辑:正如评论和其他答案所指出的,
1 | from tkinter import * |
相反,只叫