简体   繁体   English

使用grid_forget Tkinter删除帧的部分

[英]Deleting parts of a frame using grid_forget Tkinter

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: 然而,我最终得到以下结论:

表

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. 我有一个根窗口,然后是一个主窗口,'win1',其中一个框架'frame_table'包含所有的表。 The background is set to black. 背景设置为黑色。

UPDATE: Corresponds to changing options in OptionMenu: 更新:对应于更改OptionMenu中的选项:

Rather than having created seperate frames I have just created a set of entry boxes in the current frame 'frame_table'. 我没有创建单独的帧,而是在当前帧'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. 使用另一个选项,它总是创建2个盒子。 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. 因此,如果从“列表”转到“菜单中的其他选项(未修复)”,则需要在创建新框之前删除“列表”选项中的框。

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. 在python中很少需要。 Perhaps you aren't seeing your boxes removed because your self.number_boxes is incorrect (maybe you forgot to update it somewhere). 也许你没有看到你的盒子被移除,因为你的self.number_boxes不正确(也许你忘了在某处更新它)。 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. 这可能(或可能不)解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM