Please do me a favour. I am getting an error
Traceback (most recent call last):
File "C:\Users\mniza\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1885, in __call__
return self.func(*args)
File "C:\Users\mniza\OneDrive\LOL\Nizpad_spell_check_04.py", line 1576, in aaa
return CustomWidget.text_get()
TypeError: text_get() missing 1 required positional argument: 'self'
This is so annoying as I am googling and trying to find the answer for almost 2 days. I am new to coding as well as python. The code which produces this error is:
def colour_certain_text(event):
class CustomWidget(tk.Frame):
def __init__(self, parent, label, default=""):
tk.Frame.__init__(self, parent)
super().__init__(parent)
self.text_entry_label = tk.Label(self, text= "Enter the text here")
self.text_font_style_combobox_label = tk.Label(self, text= "Font Style")
self.text_font_colour_entry_label = tk.Label(self, text= "Font Colour")
self.text_entry= ttk.Entry(self)
self.text_font_style_combobox = ttk.Combobox(self, values= ["Regular", "Bold", "Italic", "Bold Italic"])
self.text_font_colour_entry= tk.Entry(self, state= "readonly", fg= "#FFFFFF")
self.text_font_colour_select_button= ttk.Button(self, text= "Select Colour")
self.customwidget_destroy_button= tk.Button(self, text="⨉ Delete", cursor = "hand2", relief= "ridge")
self.customwidget_destroy_button.bind("<Enter>", lambda event: self.customwidget_destroy_button.config(bg= "#FF0000"))
self.customwidget_destroy_button.bind("<Leave>", lambda event: self.customwidget_destroy_button.config(bg= "SystemButtonFace"))
self.text_font_style_combobox.insert(0, font_mode.get())
self.text_font_style_combobox.config(state= "readonly")
self.text_entry_label.grid(row= 0, column= 0)
self.text_font_style_combobox_label.grid(row= 0, column= 1)
self.text_font_colour_entry_label.grid(row= 0, column= 2)
self.text_entry.grid(row= 1, column= 0)
self.text_font_style_combobox.grid(row= 1, column= 1 )
self.text_font_colour_entry.grid(row= 1, column= 2)
self.text_font_colour_select_button.grid(row= 0, column= 3, rowspan= 2)
self.customwidget_destroy_button.grid(row= 0, column= 4, rowspan= 2)
def text_get(self):
return self.text_entry.get()
def font_colour_get(self):
return self.text_font_colour_entry.get()
def font_style_get(self):
return self.text_font_style_combobox.get()
colour_certain_text_win= tk.Toplevel(notepad)
a= CustomWidget(colour_certain_text_win, label= "Hello")
a.pack()
def aaa():
a_= 0
return CustomWidget.text_get()
a_btn= tk.Button(colour_certain_text_win, command= aaa)
a_btn.pack()
colour_certain_text_win.mainloop()
I hate classes as I am not so good at it. But now I can't avoid it. So plz help me to figure out what is the problem going on here. Otherwise I am quitting tkinter. Oh, By the way, My code is really very dirty. Please don't yell at me if you can't understand it.
text_geta.text_get()instead ofCustomWidget.text_get(). If you call the method on an instance, it passes the instance as the parameterself.super().__init__(parent).tk.Frame.__init__(self, parent)instead ofsuper().__init__(parent)