Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 打印输出到Tkinter文本小部件_Python 2.7_Tkinter - Fatal编程技术网

Python 2.7 打印输出到Tkinter文本小部件

Python 2.7 打印输出到Tkinter文本小部件,python-2.7,tkinter,Python 2.7,Tkinter,我有一个脚本,它使用beautifulsoup在网站上搜索产品条形码,并拼凑了一些代码,试图用Tkinter制作一个基本的GUI。首先有一个输入框来请求URL,然后我想将该设置输出到Tkinter文本小部件。这是我不能做的最后一部分。当我尝试将文本放入另一个示例中时,text.insert上出现名称错误 from Tkinter import * from ScrolledText import * import tkFileDialog import tkMessageBox import u

我有一个脚本,它使用beautifulsoup在网站上搜索产品条形码,并拼凑了一些代码,试图用Tkinter制作一个基本的GUI。首先有一个输入框来请求URL,然后我想将该设置输出到Tkinter文本小部件。这是我不能做的最后一部分。当我尝试将文本放入另一个示例中时,text.insert上出现名称错误

from Tkinter import *
from ScrolledText import *
import tkFileDialog
import tkMessageBox
import urllib2
import bs4 as bs
import re
import urlparse
import sys
master = Tk()

e = Entry(master)
e.pack()

e.focus_set()

def callback():
    url = e.get()

    response = urllib2.urlopen(url)
    content = response.read()
    soup = bs.BeautifulSoup(content)
    barcodes = set()
    for tag in soup.find_all('img', {'src': re.compile(r'/pi/')}):
        href = tag['src']
        scheme, netloc, path, query, fragment = urlparse.urlsplit(href)
        barcodes.add(path.split('\\')[1])
##    print "\n".join(str(x) for x in sorted(barcodes)) This would output to the shell.


b = Button(master, text="go", width=10, command=callback)
b.pack()
我想启动另一个文本窗口,如果它有值,则将条形码打印到其中

##if len(barcodes) != 0:
##
##        import Tkinter
##        import ScrolledText
##        root = Tkinter.Tk(className=" Just another Text Editor")
##        textPad = ScrolledText.ScrolledText(root, width=100, height=80)
##        textPad.pack()
##
##        root.mainloop()

mainloop()

我已经查阅了Tkinter文档大约一天了,但没有任何进展。如果有任何指点,我将不胜感激。目前,is说条形码没有定义,所以我显然做了一些其他的错误。

使用
text.insert
,你的确切错误是什么?因此,我做了一个从另一个站点提取的更基本的示例,它只是打开一个文本小部件,然后我输入text.insert(Tkinter.END,“hello”)。返回NameError:name'text'未定义要添加到上面,该脚本的顶部有import Tkinter&您是否在这之前编写了
text=text
?如果不是很友好的访问,非常感谢,这很有帮助。另一个问题:当我试图在代码的后半部分实现它时,它说名称条形码没有定义。但是,在脚本的前面,它被定义为一个集合,为什么需要再次定义它呢?对不起,如果这是愚蠢的。