我不知道您为什么要这样做,因为用户使用它似乎是一个令人困惑的界面,但这里有一个使用 a 的示例wx.Timer
:
import random
import wx
class TabPanel(wx.Panel):
def __init__(self, parent):
""""""
wx.Panel.__init__(self, parent=parent)
colors = ["red", "blue", "gray", "yellow", "green"]
self.SetBackgroundColour(random.choice(colors))
btn = wx.Button(self, label="Press Me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(btn, 0, wx.ALL, 10)
self.SetSizer(sizer)
class DemoFrame(wx.Frame):
"""
Frame that holds all other widgets
"""
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY,
"Notebook Tutorial",
size=(600,400)
)
panel = wx.Panel(self)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.change_tabs, self.timer)
self.timer.Start(1000)
self.notebook = wx.Notebook(panel)
tabOne = TabPanel(self.notebook)
self.notebook.AddPage(tabOne, "Tab 1")
tabTwo = TabPanel(self.notebook)
self.notebook.AddPage(tabTwo, "Tab 2")
tabThree = TabPanel(self.notebook)
self.notebook.AddPage(tabThree, 'Tab 3')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.notebook, 1, wx.ALL|wx.EXPAND, 5)
panel.SetSizer(sizer)
self.Layout()
self.Show()
def change_tabs(self, event):
current_selection = self.notebook.GetSelection()
print(current_selection)
pages = self.notebook.GetPageCount()
if current_selection + 1 == pages:
self.notebook.ChangeSelection(0)
else:
self.notebook.ChangeSelection(current_selection + 1)
if __name__ == "__main__":
app = wx.App(True)
frame = DemoFrame()
app.MainLoop()
您也可以使用 Thread 并使用类似的东西wx.CallAfter
来更新您的 UI,但我认为在这种情况下计时器更有意义。