Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.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 如何将鼠标悬停在word cloud中的单词上_Python - Fatal编程技术网

Python 如何将鼠标悬停在word cloud中的单词上

Python 如何将鼠标悬停在word cloud中的单词上,python,Python,我使用python通过名为(pytagcloud)的模块从文本文件创建了一个wordcloud,但我将其创建为.jpeg文件。但是当我将光标悬停在云中的单词上时,我想使云中的单词处于活动状态。 当我点击word cloud中的特定单词时,文章中相应的句子应该突出显示。怎么做?请帮帮我。我在这方面有项目工作。 我创建了一个gui,在其中我可以选择导入文本文件和读取文本文件。在阅读文本文件之后,我需要从.txt文件中的段落生成单词cloud def wordcloud(self):

我使用python通过名为(pytagcloud)的模块从文本文件创建了一个wordcloud,但我将其创建为.jpeg文件。但是当我将光标悬停在云中的单词上时,我想使云中的单词处于活动状态。 当我点击word cloud中的特定单词时,文章中相应的句子应该突出显示。怎么做?请帮帮我。我在这方面有项目工作。 我创建了一个gui,在其中我可以选择导入文本文件和读取文本文件。在阅读文本文件之后,我需要从.txt文件中的段落生成单词cloud

def wordcloud(self):

        from pytagcloud import create_tag_image, create_html_data, make_tags, LAYOUT_HORIZONTAL, LAYOUTS, LAYOUT_MIX, LAYOUT_VERTICAL, LAYOUT_MOST_HORIZONTAL, LAYOUT_MOST_VERTICAL
        from pytagcloud.lang.counter import get_tag_counts
        from pytagcloud.colors import COLOR_SCHEMES
        import webbrowser

        #import Tkinter
        #from tkFileDialog import askopenfilename
        #filename=askopenfilename()

        #with open(filename,'r') as f:
        #    text=f.read()

        #def create_tag_cloud(text):
        words = nltk.word_tokenize(self._contents)
        doc = " ".join(d for d in words[:70])
        tags = make_tags(get_tag_counts(doc), maxsize=100)
        create_tag_image(tags, 'sid.jpeg',size=(1600, 1200),fontname='Philosopher',layout=LAYOUT_MIX,rectangular=True)
        webbrowser.open('sid.jpeg')

没有看到您的代码,就没有什么需要更正的

然而,最好的方法是在
HTML
CSS
中输出标记云,这样就可以

在编写完HTML代码后,可以采取的一种方法是使用Javascript对单击的单词做出反应,并在身体中突出显示该单词的每一次出现

然而,有许多其他方法可能更适合,但如果没有任何背景,恐怕无法评论。无论如何,不要将标记云渲染为
jpeg
。这是静态的,没有交互能力

Edit1:提供的代码 查看github上可用的
test\u create\u html\u data(self):
函数,了解如何输出
html
CSS

请简要说明一下您的代码,Python将在每次运行
wordcloud()
方法时导入所有这些包。把他们拉到这样的地方(我为你开始了改编):


可能的答案太多,或者好的答案对于这种格式来说太长。请添加详细信息以缩小答案集或隔离可以在几段中回答的问题。请向我们展示一些代码。不管怎样,为什么要将word cloud渲染为jpeg格式?它不能以这种方式进行交互。你在做什么?web应用程序?GUI?你在使用什么技术?图像不是交互式的。您需要将word cloud导出为其他格式,如HTML,以便添加事件。如何将其另存为.html并使其成为交互式的。请帮帮我?
from pytagcloud import (create_tag_image, create_html_data, 
    make_tags, LAYOUT_MIX)
from pytagcloud.lang.counter import get_tag_counts
from pytagcloud.colors import COLOR_SCHEMES
import webbrowser

# ...the rest of your code...

def wordcloud(self):
    words = nltk.word_tokenize(self._contents)
    doc = " ".join(d for d in words[:70])

    tags = make_tags(get_tag_counts(doc), maxsize=100)
    data = create_html_data(tags, (1600,1200), layout=LAYOUT_MIX, fontname='Philosopher', rectangular=True)