如何在按钮单击中附加到 wxPython ListCtlr

问题描述

我希望有人可以帮助我。我不知道在哪里看。我正在用 wxPython 创建一个 GUI 应用程序。我会用一个 listctlr 和一个按钮来简化窗口。当您单击按钮时,我需要运行一个进程。这个过程有一个循环,用 selenium 打开浏览器,做一些处理。对于每次迭代,我想将该结果附加到 listctrl。截至目前,该列表在该过程完成之前不会更新。我希望它在每次循环迭代后更新列表。你能帮我或指出正确的方向吗?

    import sys
    import wx

    from collections import defaultdict
    from selenium import common
    from selenium import webdriver
    from selenium.webdriver.support.ui import Select


    class MainWindow(wx.Frame):

        def __init__(self,parent,title):
            super(MainWindow,self).__init__(parent,title=title)


            def process_applications(event):
                my_cursor = wx.Cursor(wx.CURSOR_WAIT)
                self.panel.SetCursor(my_cursor)
               
                for x,y in app.items():
                    index = self.list.InsertItem(sys.maxsize,student_application['FirstName'] + " " + student_application['LastName'])
                    
                    .... Process selenium and data....
                    
                    self.list.SetItem(index,1,'Success')
                    self.list.SetItem(index,2,'12452134234')
                    self.list.SetItemBackgroundColour(index,wx.GREEN)
                    my_cursor = wx.Cursor(wx.CURSOR_DEFAULT)
                    self.panel.SetCursor(my_cursor)
               
            self.panel = wx.Panel(self)

            Box = wx.BoxSizer(wx.VERTICAL)

            icon = wx.Icon()
            icon.copyFromBitmap(wx.Bitmap("icon.ico",wx.BITMAP_TYPE_ANY))
            self.SetIcon(icon)

            self.button = wx.Button(self.panel,wx.ID_ANY,'Process Applications',size=(200,50))
            self.button.Bind(wx.EVT_BUTTON,process_applications)
            self.list = wx.ListCtrl(self.panel,-1,style=wx.LC_REPORT)
            self.list.InsertColumn(0,"Student's Name",width=150)
            self.list.InsertColumn(1,'Status',wx.LIST_FORMAT_CENTER,100)
            self.list.InsertColumn(2,'Confirmation #',wx.LIST_FORMAT_RIGHT,100)
            Box.Add(self.list,wx.EXPAND)
            Box.Addspacer(5)
            Box.Add(self.button,wx.CENTER)
            Box.Addspacer(5)
            self.panel.SetSizer(Box)
            self.panel.Fit()
            self.Centre()
            self.Show(True)

    if __name__ == '__main__':
        ex = wx.App()
        MainWindow(None,'NCCCO Application Process')
        ex.MainLoop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)