擅长:python、mysql、java
<p>你必须告诉你的对象要做什么。凭空你的<code>Functions</code>实例将不知道(应该怎么做?)什么是<code>Frame</code>。你可以把<code>Frame</code>变成一个全局的,但我认为这不是一个好主意(如果你想处理多个框架实例,它就会崩溃)。所以你会写:</p>
<pre><code>class Functors:
...
def set_text(txt_frame, the_text):
"""txt_frame has to be a :class:`my_txt_frm` instance with ``self.text`` being a ``StaticText`` instance."""
txt_frame.text.SetLabel(the_text)
class my_txt_frm(wx.Frame): # do not name the derived class Frame to make more clear it is derived!
def __init__(# ...
...
self.text = wx.StaticText(#...
</code></pre>
<p>现在有趣的部分来了:如何把这些部分连接起来?你的代码中必须有这样的东西:</p>
<pre><code>funct = Functors() # the class which know how to do things on our GUI elements
frm = my_txt_frm(#...
</code></pre>
<p>几句话之后。。。你知道吗</p>
<pre><code>funct.set_text(frm, 'thenewtext')
</code></pre>
<p>因此,对于你的应用程序,它有更大的图片是必要的,以保持参考的建筑块,以便能够把他们在一起。你知道吗</p>
<p>一种有序地将事物连接在一起的方法称为MVC(<a href="https://wiki.wxpython.org/ModelViewController" rel="nofollow">see a great example in the wxPython wiki</a>)。即使您不想按照这种模式来建模应用程序,您也可以从中学习如何对关注点分离进行推理。你知道吗</p>