Problem with grid_forget in Tkinter - Python [closed]
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this questionBasically, it seems that the grid_forget() method in Tkinter only works for some widgets in my program and not for others. I want the screen to clear when I press a "restart" button, and then the starting widgets appear again, as if the user had closed and reopened the program.
Unfortunately, when I press the button, some widgets disappear and some don't. I'm using the grid_forget() method on all of them, so I'm not quite sure what the problem is. It appears that the ones that stay visible are the ones I've interacted with while the program is running - an entry widget and a button, for example. I can't find any online documentation detailing this problem, so I thought I'd ask for help.
My code (or at least, the "restart" button bit of it) is below:
def RetryButtonClick(self):
"""Note to self: this needs to be fixed"""
self.labelvar.set("")
self.textvar1.set("")
self.textvar2.set("")
self.LabelIndiv.config(state=NORMAL)
self.LabelIndiv.grid_forget
self.textEntryIndiv.config(text="", state=NORMAL)
self.textEntryIndiv.grid_forget
self.FirstEntry.config(state=NORMAL)
self.FirstEntry.grid_forget
self.LastLabelB.config(state=NORMAL)
self.LastLabelB.grid_forget
self.ImportAll.config(state=NORMAL)
self.ImportAll.grid_forget
self.OpenButtonIndiv.config(state=NORMAL)
self.OpenButtonIndiv.grid_forget
self.OpenButtonBatch.config(state=NORMAL)
self.OpenButtonBatch.grid_forget
self.RetryButton.grid_forget
self.Label3.config(text="")
self.Label5.config(text="")
开发者_开发百科 #self.master.grid_forget()
self.startwindow()
self.startwindow() is the function that defines the widgets and their location on the screen and this seems to be working perfectly fine. I'm sure the problem must be in this bit, but I'm at a loss as to what exactly. I tried changing the state to normal of the widgets, as a previous function disables them, but that doesn't seem to work. I also tried using grid_forget on the master frame self.master
, but again, that left only the widgets I'd interacted with - say, textEntryIndiv
and OpenButtonIndiv
- visible on the screen, the rest vanished as they should.
If anyone has any idea about this, I'd be very grateful for some help. I can provide more code if needed, but there's a lot of it which is why I haven't put the lot in here.
EDIT/UPDATE:
Never mind. Seems to have fixed itself without me actually doing anything - quite literally, its working without me making any changes to the code. Now I feel like posting this was kinda unnecessary. Oh well.
grid_forget
is a method. When you call it like self.textEntryIndiv.grid_forget
you aren't calling the method, you are just asking for a reference. You need to call it like self.textEntryIndiv.grid_forget()
(note the trailing ()
)
精彩评论