Reputation: 23
Can anyone tell me how to get the specific label in this case?
this is a loop so it always goes to the last item label.
I can pass the ScrolledText but cant pass the label, the label is lblspec, this (my_var_expected.set(textlabl)) works but only update the last label of the for loop
def checkval(e, spec0, spec1, spec2, spec3, spec4, spec5):
e.widget.insert("1.0", PLACEHOLDER if e.widget.get("1.0", "end-1c") == "" else "")
reqlidst=(spec0, spec1, spec2, spec3, spec4, spec5)
textlabl=""
for x in reqlidst:
x = x.replace("#", "")
x = x.replace(" ", "")
if len(x)>1:
if x.upper() in e.widget.get("1.0", "end-1c").upper():
if len(textlabl)>1:
textlabl = textlabl+ x.replace(" ", "").upper() + " " + html.unescape('✔')+"\n\n"
else:
textlabl = x.replace(" ", "").upper() + " " + html.unescape('✔')+"\n\n"
else:
if len(textlabl) > 1:
textlabl = textlabl+ x.replace(" ", "").lower() + " " + html.unescape('✘')+"\n\n"
else:
textlabl = x.replace(" ", "").lower() + " " + html.unescape('✘')+"\n\n"
my_var_expected.set(textlabl)<---- cant get this to update the correct label
print(textlabl)
for line in var_expect_result:
if len(line)>1:
x, y, y1, y2, y3, y4, y5 = line.split('<->')
y_respexpt = (y + "\n\n" + y1 + "\n\n" + y2 + "\n\n" + y3 + "\n\n" + y4 + "\n\n" + y5).replace('##', '').strip()
y_respexpt = y_respexpt.replace(' ', '').strip()
my_var_expected = StringVar()
my_var_expected.set(y_respexpt)
kiblogbn = ScrolledText(frmbtn, name="frm_"+str(x), width=25, height=30,border=2,relief="solid")
kiblogbn.grid(column=coll, row=2, padx=10, pady=10, ipady=25,sticky="W")
PLACEHOLDER = 'Copy logs from Kibana and past them here.'
kiblogbn.insert(END, PLACEHOLDER)
kiblogbn.bind("<FocusIn>", lambda e: e.widget.delete("1.0", "end-1c") if e.widget.get("1.0", "end-1c") == PLACEHOLDER else None)
kiblogbn.bind("<FocusOut>", lambda e, y=y, y1=y1, y2=y2, y3=y3, y4=y4, y5=y5: checkval(e, y, y1, y2, y3, y4, y5))
lblspec = Label(frmbtn, textvariable=my_var_expected, justify='left', anchor=N)
lblspec.grid(column=coll, row=6, rowspan=99, sticky=N, padx=20, pady=20)
Upvotes: 0
Views: 48
Reputation: 47173
One of the way is to use an attribute of kiblogbn
to save a reference of the variable my_var_expected
:
for line in var_expect_result:
if len(line)>1:
...
my_var_expected = StringVar()
my_var_expected.set(y_respexpt)
kiblogbn = ScrolledText(frmbtn, name="frm_"+str(x), width=25, height=30,border=2,relief="solid")
kiblogbn.my_var_expected = my_var_expected # save reference of variable
...
Then use e.widget.my_var_expected
inside checkval()
:
def checkval(e, spec0, spec1, spec2, spec3, spec4, spec5):
...
for x in reqlidst:
...
e.widget.my_var_expected.set(textlabl)
print(textlabl)
Upvotes: 1