所以我尝试使用语音模块制作一个相对简单的 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/