how best to clear objects from a frame

C

Chris Hare

Here is the situation:

I have a window with a bunch of widgets in it. I want to clear the objects in a given frame and recreate them to update them.

The example below destroys the top level frame, and so I can't recreate the widgets. I am likely doing this wrong.
should I be doing this in a class?


Thanks for the help.

from Tkinter import *

def createLeftWidgets(left):
#
# Add the Net Status Section
#
conditions = LabelFrame(left, text="Net Conditions",bg="Gray")
conditions.grid(row=0,column=0);
button = Button(conditions, text="Refresh", command=refreshNetConditions, highlightbackground="Green")
button.grid(row=0,column=1, sticky=E)
cText = Text(conditions,bg="Gray")
cText.insert(END, root.netHistory.get())
cText.config(height=12,width=40)
cText.grid(row=1,column=0,columnspan=2)
status = LabelFrame(left, text="Net Details",bg="Gray")
status.grid(row=1,column=0,sticky=N+E+W+S);
lblNetNumber = Label(status, text="Net Number")
lblNetNumber.grid( row=19, column=0, columnspan=2,sticky=W)
return(conditions)
def refreshNetConditions():
global frameLeft
frameLeft.destroy()
root.netHistory.set( "inserting text\n" + root.netHistory.get())
createLeftWidgets(frameLeft)

root = Tk()
root.netHistory = StringVar()
root.netHistory.set("goes into the text widget")
frame = Frame(root)
frame.grid()
frameLeft = createLeftWidgets(frame)

root.mainloop()
 
R

rantingrick

Here is the situation:

I have a window with a bunch of widgets in it.  I want to clear the objects in a given frame and recreate them to update them.  

You need to check out the "w.update" and "w.update_idletasks" methods
available on all Tkinter widgets. Just FYI: to remove a widget from
view without destroying it use "w.pack_forget" or "w.grid_forget".
However if you are simply trying to refresh a widget use one of the
update methods.
 
C

Chris Hare

You need to check out the "w.update" and "w.update_idletasks" methods
available on all Tkinter widgets. Just FYI: to remove a widget from
view without destroying it use "w.pack_forget" or "w.grid_forget".
However if you are simply trying to refresh a widget use one of the
update methods.

I will have a look at those. Consider a frame with a label and a button. How do I address the label to change it from another function in the class?
 
M

Mark Lawrence

You need to check out the "w.update" and "w.update_idletasks" methods
available on all Tkinter widgets. Just FYI: to remove a widget from
view without destroying it use "w.pack_forget" or "w.grid_forget".
However if you are simply trying to refresh a widget use one of the
update methods.

I don't understand the technical content of this thread, but I'm very
pleased to see rantingrick being positive, well done!!! :) I know that
we've crossed swords in the past but believe that bygones should be
bygones. Can we call it quits and help to take Python forward?

Kindest regards.

Mark Lawrence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top