[英]Automate Tabbing though tabs in WXnotebook
我有一本WXnotebook,它具有不同數量的選項卡,具體取決於程序提取的信息量。 我的目標是對每個選項卡顯示的信息進行屏幕截圖並存儲這些圖像。 我程序在選項卡上遇到問題 。 我在想也許
for i in range(numOfTabs):
self.waferTab.ChangeSelection(i)
time.sleep(3)
但這只會顯示wxnotebook中的最后一個標簽。 如果有人知道如何得到這個,我將非常感激。
編輯
所以我嘗試了以下建議的以下操作,但是顯示了GUI,但是當它出現時看起來它已經遍歷整個循環並顯示選擇是最后一個選項卡,但我仍然看不到屏幕實際上正在通過這些選項卡
for i in range(numOfTabs):
self.waferTab.SetSelection(i)
Refresh
wx.SafeYield()
time.sleep(10)
我不知道您為什么要這樣做,因為它似乎使用戶無法使用,但是這是使用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
類的wx.CallAfter
來更新UI,但是在這種情況下,我認為計時器更有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.