Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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 在<;字符串>';需要字符串作为左操作数,而不是StringVar_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 在<;字符串>';需要字符串作为左操作数,而不是StringVar

Python 在<;字符串>';需要字符串作为左操作数,而不是StringVar,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我正在尝试使用self.search来确定将显示.txt文件中的哪些行,即:条目为“蓝色”,它将在文本中以蓝色打印所有行。 每个按钮搜索不同的.txt文件 Tkinter回调回溯异常(最近一次调用上次):文件“C:\Users\gblmac\AppData\Local\Programs\Python\Python36-32\lib\Tkinter\uuuuu init\uuuuuu.py”,第1702行,在callreturn self.func(*args)文件“D:\Users\gblmac

我正在尝试使用self.search来确定将显示.txt文件中的哪些行,即:条目为“蓝色”,它将在文本中以蓝色打印所有行。
每个按钮搜索不同的.txt文件

Tkinter回调回溯异常(最近一次调用上次):文件“C:\Users\gblmac\AppData\Local\Programs\Python\Python36-32\lib\Tkinter\uuuuu init\uuuuuu.py”,第1702行,在callreturn self.func(*args)文件“D:\Users\gblmac\Desktop\Python Programs\Testing\GUI class和init.py”,第37行,在searchvision中,如果self.usertext in line:TypeError:“in”需要字符串作为左操作数,而不是StringVar

self.usertext = StringVar()
中的
需要字符串作为左操作数

为此

if self.usertext in line:
不是StringVar

self.usertext = StringVar()
因为左侧变量是StringVar

self.usertext = StringVar()
你需要使用

if self.usertext.get() in line:

谢谢你,这很有效。我只需要弄清楚为什么它会打印列表中的所有行,而不仅仅是包含条目string的行。我不确定,但在循环之后,您需要执行
self.search.close()