我正在使用tkinter GUI。此功能位于按钮后面。我可以调用整个函数的输出以在标签(在框架内)中显示吗?
def rules(value):
if no_of_EG==6:
print("Readability is EXTREMELY GOOD")
elif no_of_EG==5:
print("Readability is VERY GOOD")
.
.
.
// and so on many rules
rules(mapped)
tkinter代码:
leftFrame=Frame(window, bd=2, width=180, height=550)
leftFrame.pack(side=LEFT)
button5 = Button(leftFrame, text ="Rules", command=lambda:rules(mapped))
如果我这样做:
def rules(value):
if no_of_EG==6:
print("Readability is EXTREMELY GOOD")
global a
a = 'Readability is EXTREMELY GOOD'
rules(mapped)
def MF():
MFlabel1 = Label(bottomRightFrame, bg="black", fg="white", textvariale=a)
MFlabel1.grid(row=1,column=0, sticky=E)
button5 = Button(leftFrame, text ="Rules", command=MF)
这是一个非常漫长的过程,因为有40多个规则。那么如何调用整个函数的输出呢?
答案 0 :(得分:0)
使用widget.config(text=variable)
或widget['text']=variable
方法:
def MF():
MFlabel1 = Label(bottomRightFrame, bg="black", fg="white", textvariale=a)
MFlabel1.grid(row=1,column=0, sticky=E)
rules(mapped)
def rules(value):
if no_of_EG==6:
print("Readability is EXTREMELY GOOD")
global a
a = 'Readability is EXTREMELY GOOD'
MFlabel1['text'] = a
#MFlabel1.config(text=a) you can use the above line or this line.
button5 = Button(leftFrame, text ="Rules", command=MF)