使用matlibp生成后Gtk对象丢失

2024-07-07 06:25:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我的申请是这样组织的:

def __init__(self): 
    gladefile = "ui/gui.ui"
    builder = gtk.glade.XML(gladefile,"gtk_main_window")   
    gtk_main_window = builder.get_widget("gtk_main_window")  
    Main_Window(gtk_main_window, builder)  

    Tree_View(builder)
    TFIDF_Tab(builder)   
    VSM_Tab(builder)  

    gtk_main_window.show_all()

这是生成图表的代码:

        if len(results_tfidf) >= 1:    
            if len(results_tfidf) > 300:
                Main_Window.dialog.display("Too much words!")
            else:
                results_tfidf = collections.OrderedDict(sorted(results_tfidf.items(), key=lambda x : x[1], reverse=True))
                self.plot = self.tf_idf_fig.add_subplot(111)
                self.plot.cla() 
                self.plot.bar(*zip(*zip(count(), results_tfidf.values())))
                self.plot.set_title("TF IDF Chart")
                self.plot.set_xticklabels(results_tfidf.keys(),rotation='vertical',horizontalalignment='left')
                labels = range(len(results_tfidf.keys()))
                self.plot.set_xticks(labels)
                self.plot.set_xlabel("Word")
                self.plot.set_ylabel("TF*IDF") 
                self.tf_idf_canvas.draw()  
        else:  
            self.tf_idf_fig = Figure()
            self.tf_idf_fig.subplots_adjust(bottom=0.20)

            self.tf_idf_canvas = FigureCanvas(self.tf_idf_fig)  
            self.tf_idf_chart_vbox.pack_start(self.tf_idf_canvas)
            self.tf_idf_toolbar = NavigationToolbar(self.tf_idf_canvas, self.tf_idf_chart_vbox)
            self.tf_idf_chart_vbox.pack_start(self.tf_idf_toolbar,False,False, 3) 

How a chart is generated

这就是我遇到的错误:

Traceback (most recent call last):
  File "/home/badc0re/Desktop/magisterska/twitter_dataset/code/TextAnalyzer/core/vsm_tab.py", line 18, in on_vsm_process_button_clicked
    search_query = self.vsm_search_query.get_text()
AttributeError: 'VSM_Tab' object has no attribute 'vsm_search_query'

这是当我从vsm\u选项卡(向量空间模型)调用方法“on\vsm\u process\u button\u clicked”时,我不知道为什么我在为每个类处理程序调用元素时会丢失所有元素self.builder.signal\u自动连接(自)用于连接方法。你知道吗


Tags: selfgtkplotmaintfbuilderfigwindow