动态填充小部件,如何访问它们?
因此,我在这里有一个小项目,它搜索文件 (*.db) 的路径,然后为这些小部件创建一个复选框和一个文本控件。当我运行应用程序时,这部分工作得很好:
# Get a count of *.db from the filesystem
numDB = scrubDB(os.getcwd())
# Checkbox (enable, disable for launch)
# textCtrl (for Proxy name in controller)
# database name (based on *.db)
for db in numDB:
check = wx.CheckBox(self, -1, db)
sizer.Add(check, pos=(xIndex,0), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
label = wx.StaticText(panel, label="")
sizer.Add(label, pos=(xIndex,1), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
name = wx.TextCtrl(panel)
#Set Temp Name
if db.endswith('.db'):
name.Value = db[:-3]
sizer.Add(name, pos=(xIndex,2), span=(1,3),flag=wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=5)
xIndex +=1
#-------------------------------------------------------
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
这会输出类似以下内容:
[ ] test.db test
[ ] test2.db test2
但现在我需要能够访问这些小部件来构建命令。该列表可以是任意数量的.db 文件,具体取决于scrubDB 函数返回的内容。
我对 Python 和 wxPython 还很陌生,所以我很感激这里的任何指导。
So, I've got a small project here that searches a path for files (*.db) and then makes a checkbox and a text control for those widgets. This part works just fine when I run the app:
# Get a count of *.db from the filesystem
numDB = scrubDB(os.getcwd())
# Checkbox (enable, disable for launch)
# textCtrl (for Proxy name in controller)
# database name (based on *.db)
for db in numDB:
check = wx.CheckBox(self, -1, db)
sizer.Add(check, pos=(xIndex,0), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
label = wx.StaticText(panel, label="")
sizer.Add(label, pos=(xIndex,1), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=10)
name = wx.TextCtrl(panel)
#Set Temp Name
if db.endswith('.db'):
name.Value = db[:-3]
sizer.Add(name, pos=(xIndex,2), span=(1,3),flag=wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.TOP, border=5)
xIndex +=1
#-------------------------------------------------------
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
This would ouput something like:
[ ] test.db test
[ ] test2.db test2
But now I need to be able to access those widgets to build out a command. That list could be any number of .db files based on what the scrubDB function returns.
I'm still pretty new to Python and wxPython, so I would appreciate any guidance here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要动态绑定事件 -
You will need to bind the events dynamically -
这最终成功了:
我完全意识到可能有一种更智能的方法来管理元组(我在尝试解决这个问题的过程中了解到了所有这些。:)
This ended up working:
I completely realize there is probably a smarter way to manage the tuple (which I learned all about in the process of trying to figure this out. :)