0

我有一个 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)
4

1 回答 1

1

我不知道您为什么要这样做,因为用户使用它似乎是一个令人困惑的界面,但这里有一个使用 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,但我认为在这种情况下计时器更有意义。

于 2018-10-17T21:48:08.047 回答