Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 运行下面的代码段时,我遇到了一个错误_Python_Tkinter - Fatal编程技术网

Python 运行下面的代码段时,我遇到了一个错误

Python 运行下面的代码段时,我遇到了一个错误,python,tkinter,Python,Tkinter,非常感谢你的帮助!现在有了这段代码,我就可以得到文本窗口了。但是,我无法进入while循环 from tkinter import * root = Tk() T = Text(root, height=2, width=30) T.pack() T.insert(END, "Just a text Widget\nin two lines\n") root.mainloop() while(1): print("inside for loop") T.insert(END, "

非常感谢你的帮助!现在有了这段代码,我就可以得到文本窗口了。但是,我无法进入while循环

from tkinter import *
root = Tk()
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Just a text Widget\nin two lines\n")
root.mainloop()
while(1):
    print("inside for loop")
    T.insert(END, "foo")
    T.see(END)
如果我按以下方式更改代码,则不会显示文本窗口。请您告诉我如何在这里继续

from tkinter import *
root = Tk()
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Just a text Widget\nin two lines\n")
while(1):
    print("inside for loop")
    T.insert(END, "foo")
    T.see(END)
root.mainloop()

将来:请修正你的代码格式(缩进问题!),并将回溯放在你的问题中,而不是作为一个未格式化的注释

关于您的错误:这是因为您在
mainloop()
之后调用
T.insert
。在主循环完成后(例如,如果关闭窗口),您将到达代码中的该点。因为没有更多的文本区域可以插入内容,所以发生了这个奇怪的错误


除此之外,您可能希望执行
如果
Traceback(最近一次调用):文件“C:\Users\jee11\workspace\hello\jeeva\hello\text\pad.py”,第14行,在T.insert(END,“TEST”)文件“C:\python\lib\tkinter\u init.py”,第3266行,在insert self.tk.call(self.'insert',insert',index,chars)中+args)\u tkinter.TclError:命令名无效。“!text”请修复代码高亮显示。只需在代码前添加4个空格并进行缩进。