我使用的是wxPython 2.8,在我的应用程序中,当触发指定事件时,我使用wx.ListBox添加一些字符串。每次触发该事件时,我需要在wx.ListBox的顶部添加一个字符串(其他字符串随后放置)。
如果我最初是带有以下字符串的wx.ListBox:
version: '3.3'
networks:
kafka_example:
driver: overlay
services:
zookeeper-1:
image: confluentinc/cp-zookeeper:5.0.1
volumes:
- '/volumedockerkafka/zookeeper-1/zookeeper_data:/var/lib/zookeeper:rw' # mount point
- '/volumedockerkafka/zookeeper-1/zookeeper_etc:/etc/zookeeper:rw' # mount point
environment:
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
networks:
- kafka_example
zookeeper-2:
image: confluentinc/cp-zookeeper:5.0.1
volumes:
- '/volumedockerkafka/zookeeper-2/zookeeper_data:/var/lib/zookeeper:rw' # mount point
- '/volumedockerkafka/zookeeper-2/zookeeper_etc:/etc/zookeeper:rw' # mount point
environment:
ZOOKEEPER_SERVER_ID: 2
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
networks:
- kafka_example
zookeeper-3:
image: confluentinc/cp-zookeeper:5.0.1
volumes:
- '/volumedockerkafka/zookeeper-3/zookeeper_data:/var/lib/zookeeper:rw' # mount point
- '/volumedockerkafka/zookeeper-3/zookeeper_etc:/etc/zookeeper:rw' # mount point
environment:
ZOOKEEPER_SERVER_ID: 3
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_SERVERS: zookeeper-1:2888:3888;zookeeper-2:2888:3888;zookeeper-3:2888:3888
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_INIT_LIMIT: 5
ZOOKEEPER_SYNC_LIMIT: 2
networks:
- kafka_example
message_queue_kafka-1:
image: confluentinc/cp-kafka:5.0.1
volumes:
- '/volumedockerkafka/kafka-1/kafka_data:/var/lib/kafka/data:rw' # mount point
- '/volumedockerkafka/kafka-1/kafka_etc:/etc/kafka:rw'
environment:
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://message_queue_kafka-1:9092
KAFKA_BROKER_ID: 1
KAFKA_SESSION_TIMEOUT_MS: 60000
KAFKA_HEARTBEAT_INTERVAL_MS: 20000
KAFKA_REBALANCE_TIMEOUT_MS: 300000
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
networks:
- kafka_example
message_queue_kafka-2:
image: confluentinc/cp-kafka:5.0.1
volumes:
- '/volumedockerkafka/kafka-2/kafka_data:/var/lib/kafka/data:rw' # mount point
- '/volumedockerkafka/kafka-2/kafka_etc:/etc/kafka:rw'
environment:
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://message_queue_kafka-2:9092
KAFKA_BROKER_ID: 2
KAFKA_SESSION_TIMEOUT_MS: 60000
KAFKA_HEARTBEAT_INTERVAL_MS: 20000
KAFKA_REBALANCE_TIMEOUT_MS: 300000
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
networks:
- kafka_example
message_queue_kafka-3:
image: confluentinc/cp-kafka:5.0.1
volumes:
- '/volumedockerkafka/kafka-3/kafka_data:/var/lib/kafka/data:rw' # mount point
- '/volumedockerkafka/kafka-3/kafka_etc:/etc/kafka:rw'
environment:
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181'
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://message_queue_kafka-3:9092
KAFKA_BROKER_ID: 3
KAFKA_SESSION_TIMEOUT_MS: 60000
KAFKA_HEARTBEAT_INTERVAL_MS: 20000
KAFKA_REBALANCE_TIMEOUT_MS: 300000
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
networks:
- kafka_example
,下一个事件在列表框中存储字符串“ Hello”;结果必须是:
World
有可能吗?我还没有找到任何简单的方法。
谢谢
答案 0 :(得分:1)
仅使用InsertItems(list,pos)
,其中pos
为0-添加的项目将插入到声明的任何位置。即
import wx
class MainPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
initial_items = ['A reasonably long item that should cause a scrollbar to appear xxxxxx', 'another line', 'and another']
self.listbox = wx.ListBox(self, style=wx.LB_HSCROLL)
self.listbox.InsertItems(initial_items, 0)
self.AddBtn = wx.Button(self, -1, "Add Item")
self.AddBtn.Bind(wx.EVT_BUTTON, self.OnAdd)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.listbox, 1, wx.EXPAND)
sizer.Add(self.AddBtn, 0, wx.EXPAND)
self.SetSizer(sizer)
def OnAdd(self,evt):
self.listbox.InsertItems(['Hello World'], 0) #add at position zero
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "ListBox", size=(400, 400))
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(MainPanel(self), 1, wx.EXPAND)
self.SetSizer(main_sizer)
self.Layout()
self.Center()
self.Show(True)
app = wx.App()
mw = MainWindow()
app.MainLoop()