如何解决“ Nonetype”对象无法下标

时间:2020-04-03 17:32:08

标签: sqlite user-interface tkinter

使用tkinter创建字典,以显示从sqlite到文本小部件的单词含义

import tkinter as tk
import sqlite3
from tkinter import messagebox

root = tk.Tk()
root.geometry("400x500")
root.resizable(width=False, height= False)
root.title("Dic")
root.configure(background='skyblue')

########### DEF FOR SEARCH #######
def search():
    #try:
    conn= sqlite3.connect('GI_DICTION.db')
    cur= conn.cursor()
    tex.delete(1.0,"end")
    data= v.get()
    cur.execute("SELECT field2, Image FROM DICTION WHERE field1= ?", (data.lower(),))
    var= cur.fetchone()

    tex.insert(0.0, var[0])
#except:
   # messagebox.showinfo("Dic","Word not found")



########## GUI DESIGN ##############
v= tk.StringVar()
entry= tk.Entry(root, width=20,bg= "#FFFFFf",bd=2, textvariable= v)
entry.place(x=50, y= 25)

Butt= tk.Button(root, width=10, height= 1,command= search, text= "Search", bg= 
"#666699",fg="white",bd=0,font=("rockwell", 9))
Butt.place(x=190, y=25)
tex=tk.Text(root, font= ("Bahnschrift SemiLight",12),bg= "#999ccc",bd= 0,width=35,height= 10)
tex.place(x=50,y=55)

ImageLabel= tk.Label(root,font=("calibra", 9), width=30, height= 13, bg= "white")
ImageLabel.place(x=50, y= 250)

root.mainloop()

这是我遇到的错误... tex.insert(0.0,var [0]) TypeError:“ NoneType”对象不可下标

0 个答案:

没有答案