TypeError: Menus.__init__() 采用 1 个位置参数,但给出了 2 个
我对他的错误 TypeError: Menus.__init__() gets 1positional argument but 2 were Gived
感到震惊,请帮助我解决他的错误
main file: -->;
from tkinter import *
from meanu_items import *
def main():
windows = Tk()
windows.title("NotePad")
windows.minsize(width=60, height=80)
windows.config()
# Create place to write a text
text = Text(windows)
text.focus()
text.grid(pady=0.5, padx=10)
# Creating Scale
scroll = Scrollbar(windows, orient=VERTICAL, )
scroll.grid(row=0, column=1, sticky=NS + SE)
text.config(yscrollcommand=scroll.set)
scroll.config(command=text.yview)
menu = Menus(windows)
windows.mainloop()
if __name__ == '__main__':
main()
meanu_items 文件:-->
from tkinter import *
from tkinter import filedialog
SIDE_R = RIGHT
class Menus(Frame):
def __init__(self):
Frame.__init__()
self.filetypes = (
('text files', '*.txt'),
('All files', '*.*'))
self.text = Text()
self.menubar()
def menubar(self):
# Menu bar
# # File
menubar = Menu(self)
file = Menu(menubar, tearoff=0)
file.add_command(label="New")
file.add_command(label="Open", command=self.opens)
file.add_command(label="Save")
file.add_command(label="close")
file.add_separator()
file.add_command(label="Exit", command=self.quit)
menubar.add_cascade(label="File", menu=file)
# # Edit
edit = Menu(menubar, tearoff=0)
edit.add_command(label="Copy")
edit.add_command(label="Paste")
edit.add_command(label="Cute")
edit.add_command(label="Delete")
edit.add_command(label="Select All")
menubar.add_cascade(label="Edit", menu=edit)
# # Help
helps = Menu(menubar, tearoff=0)
helps.add_command(label="About")
menubar.add_cascade(label="Help", menu=help)
def opens(self):
dlg = filedialog.Open(self, filetypes=self.filetypes)
fl = dlg.show()
if fl != '':
text = self.readFile(fl)
self.text.insert(END, text)
上面的文件中也存在一些小错误(meanU_items):-->
Expected type 'Menu', got '(args: tuple[Any, ...], kwds: dict[str, Any]) -> None' instead : 50
Unresolved attribute reference 'readFile' for class 'Menus' :57
I'm shucked at his error TypeError: Menus.__init__() takes 1 positional argument but 2 were given
any one please help me to solve his error
main file: -->
from tkinter import *
from meanu_items import *
def main():
windows = Tk()
windows.title("NotePad")
windows.minsize(width=60, height=80)
windows.config()
# Create place to write a text
text = Text(windows)
text.focus()
text.grid(pady=0.5, padx=10)
# Creating Scale
scroll = Scrollbar(windows, orient=VERTICAL, )
scroll.grid(row=0, column=1, sticky=NS + SE)
text.config(yscrollcommand=scroll.set)
scroll.config(command=text.yview)
menu = Menus(windows)
windows.mainloop()
if __name__ == '__main__':
main()
meanu_items file: -->
from tkinter import *
from tkinter import filedialog
SIDE_R = RIGHT
class Menus(Frame):
def __init__(self):
Frame.__init__()
self.filetypes = (
('text files', '*.txt'),
('All files', '*.*'))
self.text = Text()
self.menubar()
def menubar(self):
# Menu bar
# # File
menubar = Menu(self)
file = Menu(menubar, tearoff=0)
file.add_command(label="New")
file.add_command(label="Open", command=self.opens)
file.add_command(label="Save")
file.add_command(label="close")
file.add_separator()
file.add_command(label="Exit", command=self.quit)
menubar.add_cascade(label="File", menu=file)
# # Edit
edit = Menu(menubar, tearoff=0)
edit.add_command(label="Copy")
edit.add_command(label="Paste")
edit.add_command(label="Cute")
edit.add_command(label="Delete")
edit.add_command(label="Select All")
menubar.add_cascade(label="Edit", menu=edit)
# # Help
helps = Menu(menubar, tearoff=0)
helps.add_command(label="About")
menubar.add_cascade(label="Help", menu=help)
def opens(self):
dlg = filedialog.Open(self, filetypes=self.filetypes)
fl = dlg.show()
if fl != '':
text = self.readFile(fl)
self.text.insert(END, text)
some minor error are also there in above file(meanU_items):-->
Expected type 'Menu', got '(args: tuple[Any, ...], kwds: dict[str, Any]) -> None' instead : 50
Unresolved attribute reference 'readFile' for class 'Menus' :57
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很难说,但也许您打算传入
windows
参数以将其传递到Frame
超类:Its difficult to tell, but perhaps you meant to pass in the
windows
parameter to pass it onto theFrame
super class:Menu 类正在询问“self”,
但您给它的是一个窗口对象,而不是 Menus 对象。在 init: 中写入此内容
并创建 Menus 对象,如下所示:-
Menu class is asking 'self'
but instead of a Menus object you gave it a window object. Write this in init:
and create Menus object like this:-