Question

I have used the following code to delete a section of my frame (wish to delete the number of boxes currently showing - this can vary):

for i in xrange(self.number_boxes):

    self.box[i].grid_remove()
    self.choice_title.grid_remove()

I however end up with the following:

Table

What am I doing wrong to be stuck with the last part of the main window staying there?!

I have the root window, then a main window, 'win1' in which a frame 'frame_table' holds all the table. The background is set to black.

UPDATE: Corresponds to changing options in OptionMenu:

Rather than having created seperate frames I have just created a set of entry boxes in the current frame 'frame_table'. When a 'list' option is chosen, the user inputs the amount of boxes to be created. With the other option it's always 2 boxes which are created. With the 'fixed' value, all boxes need to be deleted as no additional boxes are required.

Therefore, if one goes from 'list' to 'other option in menu (not fixed)', the boxes from the 'list' option need to be deleted prior to creating the new boxes.

Was it helpful?

Solution

The idiom:

for i in xrange(self.number_boxes):

    self.box[i].grid_remove()
    self.choice_title.grid_remove()

should rarely be necessary in python. Perhaps you aren't seeing your boxes removed because your self.number_boxes is incorrect (maybe you forgot to update it somewhere). A better way to do it is:

for box in self.boxes:
    box.grid_remove()
else:
    self.choice_title.grid_remove()

This may (or may not) solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top