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
CodePudding user response:
Its difficult to tell, but perhaps you meant to pass in the windows
parameter to pass it onto the Frame
super class:
class Menus(Frame):
def __init__(self, windows):
Frame.__init__(windows)
...
CodePudding user response:
Menu class is asking 'self'
class Menus(Frame):
def __init__(self):
but instead of a Menus object you gave it a window object. Write this in init:
class Menus(Frame):
def __init__(self, windows):
and create Menus object like this:-
menu = Menus(menus_items.Menus, windows)