使用matlibplot生成后,Gtk对象丢失

时间:2013-08-01 16:35:17

标签: python gtk

这就是我的应用程序的组织方式:

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_Tab(向量空间模型)调用方法“on_vsm_process_button_clicked”时,我不知道为什么在我为每个类处理程序self.builder.signal_autoconnect(self)连接时,为什么我会松开所有元素方法

1 个答案:

答案 0 :(得分:0)

我通过将整个应用程序迁移到GTK3解决了这个问题,但 * 有点痛苦,但值得。