如何从wxpython gui的同一按钮中打开两个不同的pylab图形? [英] How can I open two different pylab figures from the same button from a wxpython gui?

查看:113
本文介绍了如何从wxpython gui的同一按钮中打开两个不同的pylab图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,但有一个严重的问题无法克服.我使用wxpython创建了一个gui,它具有两个文本字段和一个按钮.当按下此按钮时,我调用一个函数,该函数调用另一个函数,该函数根据文本框中的输入创建一个饼图.问题是,如果用户不关闭图形并在文本框中输入新值并再次按下按钮,则程序将崩溃,而不是显示第二个图形.按下按钮时,我尝试创建不同的线程,结果是相同的.

I am new to python and I have a serious problem that I cannot overcome. I have created a gui using wxpython that has two text fields and a button. When this button is pressed I call a function that call another function which creates a pie figure according to the input in text boxes. The problem is that if the user do not close the figure and enter new values to the textboxes and press again the button, the program crash instead of showing a second figure. I tried to create different threads when the button is pressed the result is the same.

更具体地说:

这是单击按钮时调用的功能:

this are the functions that are called when the button is clicked:

def statistics_button(事件):

def statistics_button(self,event):

   t=threading.Thread(target=self.m_button21OnButtonClick,args=(event,))
    t.start()
    print t    

def m_button21OnButtonClick( self, event ):

    '''some code here'''


    fig=statistics.mmr_dist(mmr1,mmr2) 

    show()

首先调用statistics_button,然后调用m_button21OnButtonClick. statistics.mmr_dist函数如下:

the statistics_button is called first and then this calls the m_button21OnButtonClick. the statistics.mmr_dist function is the following:

'''some code'''
fig=pylab.figure(tit,figsize=(8,8),frameon=False)

ax=pylab.axes([0.1, 0.1, 0.8, 0.8])
pita=pylab.pie(db.values(), labels=tuple(db.keys()), autopct='%1.1f%%', shadow=True)
ti="%s-%s\n Maximum Distance = %s m\n Minimum Distance = %s m" % (ddf1.label,ddf2.label,maxdist,mindist)
title(ti, bbox={'facecolor':'0.8', 'pad':5}) 


'''some code'''

return fig

到目前为止,我已经了解到show()命令阻止了m_button21OnButtonClick函数的完成,因此,除非关闭图形,否则单击按钮时将无法再次调用它.但这就是我实现不同线程的原因.尽管它似乎不起作用.

So far I have understood that the show() command blocks the function m_button21OnButtonClick from finishing so it cannot be called again when the button is clicked unless the figure is closed. But this is the reason I implemented different threads. Though it doesn't seem to work.

推荐答案

请参见

See this page for advice on getting pylab to work with wxPython--which you probably shouldn't really try (see next paragraph). The problem is that pylab uses Tkinter which is incompatible with a running copy of wxPython.

最终,您应该在wxPython中嵌入绘图.效果很好,无论如何都是更好的用户体验.

Ultimately, you should just embed your plots in wxPython. That works very well and is a better user experience anyway.

这篇关于如何从wxpython gui的同一按钮中打开两个不同的pylab图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆