【问题标题】:Dynamically change the choices in a wx.ComboBox()动态更改 wx.ComboBox() 中的选项
【发布时间】:2010-10-15 12:55:15
【问题描述】:

我没有找到比将旧的 ComboBox 换成新的更好的方法来更改 wx.ComboBox() 中的不同选项。有没有更好的办法?

欧尔扬·彼得森

#!/usr/bin/python

#20_combobox.py

import wx
import wx.lib.inspection

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.p1 = wx.Panel(self)
        lst = ['1','2','3']
        self.st = wx.ComboBox(self.p1, -1, choices = lst, style=wx.TE_PROCESS_ENTER)

        self.st.Bind(wx.EVT_COMBOBOX, self.text_return)


    def text_return(self, event):
        lst = ['3','4']
        self.st = wx.ComboBox(self.p1, -1, choices = lst, style=wx.TE_PROCESS_ENTER)


class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, '20_combobox.py')
        frame.Show()
        self.SetTopWindow(frame)
        return 1

if __name__ == "__main__":
    app = MyApp(0)
#    wx.lib.inspection.InspectionTool().Show()
    app.MainLoop()

【问题讨论】:

    标签: python wxpython wxwidgets


    【解决方案1】:

    wx.ComboBox派生自wx.ItemContainer,它有AppendingClearingInsertingDeleting项的方法,所有这些方法都在wx.ComboBox上可用。

    一种方法是按如下方式定义 text_return() 方法:

    def text_return(self, event):
        self.st.Clear()
        self.st.Append('3')
        self.st.Append('4')
    

    【讨论】:

    • 或 self.sf.AppendItems(['3', '4'])
    • @Toni Cool 我一直在寻找那个 - 但由于某种原因,该功能没有记录。
    • 谢谢。 AppendItems 在新文档中,但不在旧文档中。
    • 可以通过wxpython.org/Phoenix/docs/html/…联系文档
    • 更新:文档链接已关闭
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多