wxpython传递信息,指针?
我正在尝试编写一个应用程序来帮助我跟踪我的学生。基本上是定制的笔记本/成绩簿。去年夏天我编写了一些对去年有效的东西,但我需要更好的东西。
我将从数据库中提取每个学生的记录,将其显示在我的主页上,并具有可单击的元素以打开框架,以便我可以对其进行编辑。我需要在这两个框架之间传递信息,但我是个白痴,因为我似乎不知道如何改变我遇到的显示 lambda 和同类信息传递的示例。
在我的主窗口上,我有一个如下所示的 StaticText
self.q1a_lbl = wx.StaticText(id=wxID_MAINWINDOWQ1A_LBL, label=u'87%',
name=u'q1a_lbl', parent=self.alg_panel, pos=wx.Point(115, 48),
size=wx.Size(23, 17), style=0)
self.q1a_lbl.SetToolTipString(u'Date \n\nNotes')
self.q1a_lbl.Bind(wx.EVT_LEFT_UP, self.OnQ1a_lblLeftUp)
然后我有以下功能:
def OnQ1a_lblLeftUp(self, event):
import quiz_notes
quiz_notes.create(self).Show(True)
该功能以图形方式工作,但除了单击文本时打开一个窗口之外,我实际上没有做任何其他事情。然后我有另一个框架,
import wx
def create(parent):
return quiz_notes(parent)
[wxID_QUIZ_NOTES, wxID_QUIZ_NOTESCANCEL_BTN, wxID_QUIZ_NOTESDATEPICKERCTRL1,
wxID_QUIZ_NOTESENTER_BTN, wxID_QUIZ_NOTESPANEL1, wxID_QUIZ_NOTESTEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(6)]
class quiz_notes(wx.Frame):
def _init_ctrls(self, prnt):
...and so on
我想传递至少几个变量。最终,当我开始将数据库集成到其中时,我只会传递一个元组。或者对它的引用。在 C 中我只使用一个指针。无论如何,进行更改,然后返回到我的主窗口。简而言之,处理这两个类之间的数据的最佳方法是什么?
I'm trying to code up an application to help me keep track of my students. Basically a customized notebook/gradebook. I hacked something together last summer that worked for this past year, but I need something better.
I'm going to pull each students record from a database, display it on my main page and have elements clickable to open a frame so that I can edit it. I need to pass information between these two frames and I'm an idiot because I can't seem to figure out how to alter the examples I've come across showing lambdas and same-class information passing.
On my main window I have a StaticText that looks like this
self.q1a_lbl = wx.StaticText(id=wxID_MAINWINDOWQ1A_LBL, label=u'87%',
name=u'q1a_lbl', parent=self.alg_panel, pos=wx.Point(115, 48),
size=wx.Size(23, 17), style=0)
self.q1a_lbl.SetToolTipString(u'Date \n\nNotes')
self.q1a_lbl.Bind(wx.EVT_LEFT_UP, self.OnQ1a_lblLeftUp)
Then I have the function:
def OnQ1a_lblLeftUp(self, event):
import quiz_notes
quiz_notes.create(self).Show(True)
Which works graphically, but I'm not really doing anything other than opening a window when the text is clicked on. Then I have another Frame with
import wx
def create(parent):
return quiz_notes(parent)
[wxID_QUIZ_NOTES, wxID_QUIZ_NOTESCANCEL_BTN, wxID_QUIZ_NOTESDATEPICKERCTRL1,
wxID_QUIZ_NOTESENTER_BTN, wxID_QUIZ_NOTESPANEL1, wxID_QUIZ_NOTESTEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(6)]
class quiz_notes(wx.Frame):
def _init_ctrls(self, prnt):
...and so on
I would like to pass at least a couple of variables. Eventually, when I start integrating the database into it, I would just pass a tuple. Or a reference to it. In C I'd just use a pointer. Anyway, make changes and then go back to my main window. In short, whats the best way to work with data between these two classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 中没有指针,但有可变结构。您可以通过将相同的状态对象传递给多个实例来在对象之间共享状态。
该状态对象应该是什么完全取决于您想要做什么(我仍然不知道)。它可以是任何可变的东西,模块、类、实例、字典或列表。
在此示例中,共享状态是全局变量中的列表:
There are not pointers in Python, but there are mutable structures. You can share state between objects by handing the same state-object to multiple instances.
What that state-object should be depends entirely on what you're trying to do (I still have no idea). It could be anything mutable, a module, class, instance, dict or list.
In this example the shared state is a list in a global variable:
查看 Mike Driscoll 的 有关使用的博客文章wxPython 中的 PubSub。
它使用 wxPython 中包含的 PubSub - 只需注意它是一个 独立库,并且最新版本的API与wx中包含的API不同(如果我可以这么说,是一个更好的API)
Check out Mike Driscoll's blog post on using PubSub in wxPython.
It's using the included PubSub in wxPython - just be aware that it is a stand-alone library, and the latest version's API is different to the one included in wx (a better API, if I may say so)