wxPython:如何从各个笔记本面板引用框架的状态栏?
我确信这对你们来说很容易,但我很难找到解决方案...
我有一个由一堆导入文件构建的框架来构建笔记本...类似:
class myFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY, "My Frame", size=(520,635))
panel = wx.Panel(self)
notebook = myFrameNotebook(panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
panel.SetSizer(sizer)
self.CreateStatusBar(style=0)
self.SetStatusText("Welcome to My Frame...")
self.Layout()
self.Show()
self.Centre()
我想从笔记本的各个页面中更改整个框架的状态文本...如果上面的内容称为 myFile,有没有办法从单独的笔记本页面中 SetStatusText
(它存储在一个单独的文件中?)
我想要做什么,对于例如,当您从笔记本页面移动到笔记本页面时,状态栏会反映您当前在应用程序中的位置...?
非常感谢,
Chow(对 wxPython 还是个新手)
I'm sure this is easy for you guys, but I'm having a hard time finding a solution to this...
I have a Frame that is constructed of a bunch of imported files to build a notebook... something like:
class myFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY, "My Frame", size=(520,635))
panel = wx.Panel(self)
notebook = myFrameNotebook(panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
panel.SetSizer(sizer)
self.CreateStatusBar(style=0)
self.SetStatusText("Welcome to My Frame...")
self.Layout()
self.Show()
self.Centre()
I would like, from within the individual pages of the notebook to change the Status Text of the entire frame... If the above is called myFile, is there a way to SetStatusText
from within a separate notebook page (which is stored in a separate file?)
What I'd like to do, for instance, is when you move from notebook page to notebook page, the status bar reflects where inside the application you currently are...?
Thanks much,
Chow (still new to wxPython)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,最好使用 PubSub,以解耦类对另一个类的依赖关系(并减少 GetParent().GetParent() 噪音:))
It's best to use PubSub for this, to decouple your class' dependencies on another (and to reduce that GetParent().GetParent() noise :) )
尝试这样的事情(对Python不太熟悉,但这是我在C++中要做的)。在你的构造函数中:
在你的 Frame 类中编写一个新方法:
我没有安装 wxPython,所以这是未经测试的,但这是一般的想法。这将设置状态栏以反映所选页面的标题。如果您需要它来显示页面中存储的一些其他数据,您可能可以利用 Python 的动态性,只需向每个页面添加一个属性:
Try something like this (not very familiar with Python but this is what I would do in C++). In your constructor:
Write a new method in your Frame class:
I don't have wxPython installed so this is untested, but it's the general idea. This will set the status bar to reflect the title of whatever page is selected. If you need it to show some other data that is stored in the page, you could probably take advantage of Python's being dynamic and just add a property to each page: