'Text widget is not getting removed in Tkinter code

I have created a survey where I am calling a comment_box (text widget) when I ask an objective question and call subj_ans (text widget) box where I ask subjective question.

The problem I am not able to figure out that when I call display_entry() method the code is not removing comment_box.

I am sharing my code below which is definitely not of great quality as I am newbie.

Appreciate any help I can get.

Thanks a lot in advance.

        def display_entry(self):
            print("I am inside entry")
    
            for widget in self.q_list:
                widget.grid_remove()
            if self.comment_box is not None:
                print("removing cbox")
                self.comment_box.grid_remove()
            self.subj_ans = Text(survey_frame, width=50, height=6)
            self.subj_ans.grid(row=3, column=0, columnspan=4, sticky="e")
    
        def display_comment_box(self):
    
            self.comment_box = Text(survey_frame, width=50, height=6)
            self.comment_box.grid(row=3, column=0)
    
 


Solution 1:[1]

Ok. I think I've figured out the problem. if you want to remove the comment box I think you need to do self.comment_box.destroy(). This completely removes the comment_box and then you can create a new one in display_comment_box. Does this work for you? If not, let me know!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TRCK