python - 如何获取在 wxpython 循环期间创建的 TextCtrl 的值

标签 python wxpython

假设我正在使用这样的循环创建 6 个文本控制字段:

ticker_items = ['bid', 'ask', 'open', 'close', 'high', 'low']
for item in ticker_items:
    wx.TextCtrl(self.panel, -1, value=item, size=(-1, -1))

创建后如何更新这些内容?

最佳答案

你不能。 您要么必须以某种方式保存对象(例如对象列表),要么为每个 TextCtrl 提供不同的 ID。

例如:

ticker_items = [('bid', 1000), ('ask', 1001),
                ('open', 1002), ('close', 1003),
                ('high', 1004), ('low', 1005)]

for item, id in ticker_items:
    wx.TextCtrl(self.panel, id=id, value=item, size=(-1, -1))

然后就可以使用了

my_textctrl = self.panel.FindWindowById(id_of_my_ctrl)

获取特定的控件

或者,使用列表:

ticker_items = ['bid', 'ask', 'open', 'close', 'high', 'low']
self.my_controls = []
for item in ticker_items:
    text_control = wx.TextCtrl(self.panel, -1, value=item, size=(-1, -1))
    self.my_controls.append(text_control)

你检索你的文本号码 0 用

 my_textctrl = self.my_controls[0]

关于python - 如何获取在 wxpython 循环期间创建的 TextCtrl 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15665022/

相关文章:

python - WxPython、Windows Vista 64 位和失败

python - 你如何强制 wx.ListCtrl 滚动条自动锁定到底部,以便在窗口中显示最新的数据?

python - AuiNotebook - 获得点击选项卡

python - Reportlab 将报告合并为一个 PDF

Python 按两列或更多列进行分组

python - 在 dockerfile 中自定义 ONBUILD 环境

python - 如何在 python 中循环 optparse.OptionGroup 值

python 预期: SSHing then updating the date

coding-style - wx.Frame样式位掩码中使用的所有样式参数的列表