首页 > 解决方案 > 为什么 TextBox 没有属性“插入”?

问题描述

我需要在 ListBox 中按结果过滤 CSV 文件,并将结果显示在 Text 小部件中。当我使用此搜索功能时说文本没有属性“插入”。

我需要为我的家庭作业做这件事。我尝试了在这个站点和许多其他站点中可以找到的所有内容,但没有解决问题

global search_input
with open(f, 'r', encoding = 'utf-8') as f_in: 
    for line in f_in:
       line = line.strip()
       global row
       row = []
       if search_input in line:
          row.append(line)

TextBox = tkinter.Text(root, height=20, width=30,state='disabled').grid(row=2,column=0,)
TextBox.insert('end',*row)

标签: pythontkinter

解决方案


他有:

import tkinter as tk

root = tk.Tk()
text_box = tk.Text(root, height=2, width=30)
text_box.pack()
text_box.insert(tk.END, "Text\ntext\n")
tk.mainloop()

推荐阅读