python - (不再寻求答案)如何使用wxpython实时重置组合框的选择?

标签 python combobox wxpython

所以我尝试使用语音模块制作一个相对简单的 TTS 程序。我遇到的问题是:我想通过窗口中的组合框创建一个已保存文本的列表,如果您从中添加或删除任何预设,则在重新加载程序之前它不会更新选择。有没有办法实时更新选择?

组合框初始化如下:

#I have a previously set txt file with a list of presets, and its partial destination saved in a variable "savefile"
fh = open(savefile + '//presets.txt')
presets = fh.read().split('\n')
self.presetList = presets
#self.presetList is now the list of choices for the combobox, causing it to update upon loading the program
self.presetbox = wx.ComboBox(self, pos=(90, 100), size=(293, -1), choices=self.presetList, style=wx.CB_READONLY)
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.presetbox)

然后,比如说,要清除所有选择,我需要这样的东西:

self.emptyList = []
self.presetbox.SetChoices(self.emptyList)

有办法做到这一点吗?如果是这样那就太好了! :)

最佳答案

ComboBox 是 TextCtrl 和 ListBox 的混合 ( http://wxpython-users.1045709.n5.nabble.com/Question-on-wx-ComboBox-Clear-td2353059.html )

要重置字段,可以使用 self.presetbox.SetValue('')

(如果您的组合框不是只读)

关于python - (不再寻求答案)如何使用wxpython实时重置组合框的选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25735692/

相关文章:

python - Nginx 不为我的 Flask 网站提供服务

python - 为什么 0.1 * 10 在 python 中等于 1.0?

python 3 Tkinter ComboBox 没有获得值(value)

wxPython wx.TextCtrl 动态调整大小以填充面板宽度

python - 设置文件应该存储在哪里?

python - 字典获取方法行为

python - 使用 xpath 查找表元素中的所有 tr?

javascript - 来自本地数组的 ExtJs Combobox

数组中的 C# ComboBox 项

python - 如何在 wxPython TextCtrl 中捕获在单独进程中运行的 shell 脚本的输出?