【发布时间】:2021-09-04 14:07:02
【问题描述】:
谁能告诉我在这种情况下如何获取特定标签?
这是一个循环,所以它总是转到最后一个项目标签。
我可以传递 ScrolledText 但不能传递标签,标签是 lblspec,这个 (my_var_expected.set(textlabl)) 有效但只更新 for 循环的最后一个标签
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)
【问题讨论】:
-
textlabl = textlabl, x.replace(" ", "").upper() + ":VALID:"是字符串吗?还是一个元组?而x始终是reqlidst中的最后一项。 -
它是一个字符串,已经更改了我的代码。 x 是来自 reqlidst 的值,例如:reqlidst=one,word,to,rule,them,all
-
如果您对所有标签使用一个
StringVar,那么显然所有标签将具有相同的值,请提供一个minimal reproducible example,您也可以简单地使用def checkval(e, *args),然后您可以简单地使用@ 987654328@ 因为它已经是您在第一个参数之后指定的许多值的元组
标签: python python-3.x tkinter