在Tkinter中将数值传递给scrolledtext小部件

时间:2019-04-22 13:07:44

标签: python tkinter

Tkinter回调中的异常 追溯(最近一次通话):

File "C:\Users\USER1\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:/Users/USER1/AppData/Local/Programs/Python/Python37/newWidget.py", line 54, in clickedEvaluate
    txt.insert(END,s[i] +">>>>>>>>>" + Dicesim + "\n")
TypeError: can only concatenate str (not "StringVar") to str

上面的文本显示错误消息

Dicesim=StringVar()


def clickedEvaluate():
    if txt1.get()=='':    
        messagebox.showerror('Empty entry', 'You have not entered the required first text for comparison')
        txt1.focus()

    else:
        combo = Combobox(window)
        combo['values']= ('Dice', 'Bigram', 'Trigram', 'Set-Based','NS-Sim')
        combo.current(0) #set the selected item
        combo.grid(column=0, row=4)

        file=open('db_word.txt','r')
        s=file.readlines()

        txt = ScrolledText(window,width='50',height='10',wrap=WORD)
        txt.grid(column=1,row=6)
        #txt.pack()
        if combo.get()=='Dice':
            for i in range(20):
                Dicesim.set(dice(txt1.get(),s[i]))
                txt.insert(END,s[i] +">>>>>>>>>" + Dicesim + "\n")
                txt.yview(END)

预期结果将显示 's [i] +“ >>>>>>>>>” + Dicesim +“ \ n”“。在执行dice()的一行中执行此操作时,在StringVar方法中无法识别Dicesimtxt.insert

0 个答案:

没有答案