I am looking for a method to create widgets (most likely a Label) ad nauseam, with the caveat that they can be removed or unpacked later on.
I can generate the widgets just fine, but they are not assigned a name. I do not understand how I would, if it is possible, remove a certain anonymous widget.
My first instinct was to dynamically create variable names with a stable convention, but that may unnecessarily open a can of worms. The idea is expressed below. I'd like to be able to remove a certain Button widget while not knowing at run-time how many I will handle. Thank you.
from Tkinter import *
import time
import ttk
def onDoubleClick(event):
item = t.selection()
#print "you clicked on", t.item(item,"text")
if (t.item(item,"text")=="Start IO"):
Button2 = Button(frame2,text="Button2",command=but).pack()
def but():
pack_forget()
root=Tk()
root.geometry("800x300")
frame1 = Frame(root)
frame2 = Frame(root)
t=ttk.Treeview(frame1)
t.heading("#0",text="Test steps")
t.insert("",0,"IO",text="IO")
t.insert("IO","end",text="Start")
t.bind("<Double-1>", onDoubleClick)
t.pack()
frame1.pack(side=LEFT)
frame2.pack(side=LEFT)
EDIT: My feature request was admittedly short-sighted. My ultimate goal is to have a Label widget and a Button side-by-side, both comprising what is to be a 'step' in a test launcher. Clicking the button will remove both itself and its respective Label from the GUI. I'm able to create both widgets and delete either one of them on the Button's callback, but to pack_forget both I believe I need to def a function. I believe my problem lies in passing a correct reference to def removeStep A use case is diagrammed below: ....[If this could be solved my RTFM please feel free to let me know, I just couldn't find it]
TEST: Make a PB&J
Step 0: Get Bread [Remove step]
Step 1: Smear PB [Remove step]
Step 2: Smear Jelly [Remove step]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…