简体   繁体   English

tkinter文本小部件typeError

[英]tkinter text widget typeError

I have a problem with a typeError in tkinter. 我在tkinter中遇到typeError问题。 I wrote this tiny test program to illustrate my problem: 我写了这个小小的测试程序来说明我的问题:

from tkinter import *

window = Tk()

Text(window, width=67, height=10).grid()
Text.insert(END, "test")

window.mainloop()

When I run the program, I get this error: 运行程序时,出现以下错误:

TypeError: insert() missing 1 required positional argument: 'chars' TypeError:insert()缺少1个必需的位置参数:'chars'

However, I have no idea what this argument is. 但是,我不知道这个说法是什么。 It is not said or used in any tutorial I see ( effbot for example) 我看到的任何教程都没有提到或使用它(例如effbot

I'm sure there is something really simple I'm overlooking, but I can't find it for the life of me. 我敢肯定,我确实忽略了一些非常简单的事情,但是我一生都找不到。

Thanks in advance for any help! 在此先感谢您的帮助!

You haven't set your text widget to a variable, even if you had grid returns None so it still wouldn't work: 您尚未将文本窗口小部件设置为变量,即使您的grid返回None,也仍然无法使用:

from tkinter import *
window = Tk()
my_text = Text(window)
my_text.grid()
my_text.insert(END, "test")
window.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM