tkinter的label对象无法调用的问题



```python
from tkinter import *
from tkinter.ttk import *


def calc(event):
    a = float(t1.get())
    b = float(t2.get())
    dic = {0: a + b, 1: a - b, 2: a * b, 3: a / b, 4: a ** b, 5: a % b
        , 6: compare1, 7: compare2, 8: compare3, 9: compare4}
    c = dic[comb.current()]
    lbl.config(text=str(c))


# 比大小
def compare1():
    a = float(t1.get())
    b = float(t2.get())
    if a > b:
        lbl(text="第一个数大于第二个数")
    elif a == b:
        lbl(text="第一个数大于第二个数")
    else:
        lbl(text="第一个数大于第二个数")


# 逻辑与运算
def compare2():
    a = float(t1.get())
    b = float(t2.get())
    lbl1 = Label(text=str((a, "and", b, "=", a and b)))
    lbl1.place(relx=0.6, rely=0.4, relwidth=0.2, relheight=0.3) 


# 逻辑或运算

def compare3():
    a = float(t1.get())
    b = float(t2.get())
    lbl(text=print(a, "or", b, "=", a or b))


# 逻辑非运算
def compare4():
    a = float(t1.get())
    b = float(t2.get())
    lbl(text=print(a, "的非运算结果为", not a))


root = Tk()
root.geometry('320x240')
root.title('多功能计算器')

t1 = Entry(root)
t1.place(relx=0.1, rely=0.1, relwidth=0.2, relheight=0.1)

t2 = Entry(root)
t2.place(relx=0.5, rely=0.1, relwidth=0.2, relheight=0.1)

var = StringVar()

comb = Combobox(root, textvariable=var,
                values=['加', '减', '乘', '除', '乘方', '余数', '比大小', '逻辑"与"预算', '逻辑"或"运算',
                        '逻辑"非"运算'])
comb.place(relx=0.1, rely=0.5, relwidth=0.35)
comb.bind('<>', calc)

lbl = Label(root, text='结果')
lbl.place(relx=0.6, rely=0.4, relwidth=0.2, relheight=0.3)

root.mainloop()



老师好,我的问题是我自己def的运算函数的运算结果怎么跟最后lbl结果绑定关系啊?
就是我想在结果栏显示我print的内容!自己打的结果栏显示“<function"
我def的都是实验的应该是错的 望纠正感谢!!!


> 
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/92903633017612.png "#left")

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/233736330176111.png "#left")

有几个问题
1.用字典的方式,在字典赋值的时候,会将所有方法都调用一遍,相当于计算了不需要的方法,影响效率
建议先判断选择项大小,大于7的直接写分支调用代码
2.方法需要有返回值,直接将返回值更新到label上,调用时需要加括号
3.后面计算时,需要有字符类型等输入值判断,更严谨
修改后的代码如下:
4.计算方法返回的字符串没有处理,直接拷贝原有内容,如果为了显示更好看,使用占位符方法


from tkinter import *
from tkinter.ttk import *


def calc(event):
    a = float(t1.get())
    b = float(t2.get())
    dic = {0: a + b, 1: a - b, 2: a * b, 3: a / b, 4: a ** b, 5: a % b
        , 6: compare1(), 7: compare2(), 8: compare3(), 9: compare4()}
    print(comb.current())
    c = dic[comb.current()]
    lbl.configure(text=str(c))



# 比大小
def compare1():
    a = float(t1.get())
    b = float(t2.get())
    if a > b:
        #lbl.configure(text="第一个数大于第二个数")
        result = "第一个数大于第二个数"
    elif a == b:
        #lbl.configure(text="第一个数大于第二个数")
        result = "第一个数等于第二个数"
    else:
        #lbl.configure(text="第一个数大于第二个数")
        result = "第一个数小于第二个数"
    return result


# 逻辑与运算
def compare2():
    a = float(t1.get())
    b = float(t2.get())
    # lbl1 = Label(text=str((a, "and", b, "=", a and b)))
    # lbl1.place(relx=0.6, rely=0.4, relwidth=0.2, relheight=0.3)
    #lbl.configure(text=str((a, "and", b, "=", a and b)))
    result = str((a, "and", b, "=", a and b))
    return result

# 逻辑或运算

def compare3():
    a = float(t1.get())
    b = float(t2.get())
    #lbl.configure(text=print(a, "or", b, "=", a or b))
    result = str((a, "or", b, "=", a or b))
    return result


# 逻辑非运算
def compare4():
    a = float(t1.get())
    b = float(t2.get())
    #lbl.configure(text=print(a, "的非运算结果为", not a))
    result = str((a, "的非运算结果为", not a))
    return result


root = Tk()
root.geometry('320x240')
root.title('多功能计算器')

t1 = Entry(root)
t1.place(relx=0.1, rely=0.1, relwidth=0.2, relheight=0.1)

t2 = Entry(root)
t2.place(relx=0.5, rely=0.1, relwidth=0.2, relheight=0.1)

var = StringVar()

comb = Combobox(root, textvariable=var,
                values=['加', '减', '乘', '除', '乘方', '余数', '比大小', '逻辑"与"预算', '逻辑"或"运算',
                        '逻辑"非"运算'])
comb.place(relx=0.1, rely=0.5, relwidth=0.35)
comb.bind('<<ComboboxSelected>>', calc)

lbl = Label(root, text='结果')
lbl.place(relx=0.6, rely=0.4, relwidth=0.2, relheight=0.3)

root.mainloop()

能把图片发上来吗,不是很明白你描述的现象