0

我正在按照此链接使用 selenium 自动化编写表单填写自动化脚本。因此,每当我按下“每周运行”按钮时,GUI 都会冻结并显示无响应消息。选项卡的目的是一次运行多个配置文件。搜索了很多,我也实现了线程,但它没有帮助。这是代码:

class GUI(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("SC")
        self.geometry('375x600')
        self.resizable(width=False, height=False)

        names = ['Tab 1', 'Tab 2', 'Tab 3', 'Tab 4']
        self.nb = self.create_notebook(names)
        self.menu = self.create_menus()

        self.mainloop()

    def create_notebook(self, names):
        nb = MyNotebook(self, names)
        self.domain = '127.0.0.1'

        nb.pack()

        def weekly_label(parent):
            label = tk.Label(parent, text="Press to : ")
            label.grid(column=0, row=5, padx=10, pady=10)
            return label

        def weekly_button(parent):
            weekly = ttk.Button(parent, text="Run Weekly Application", width=30,
                                command=lambda: threading.Thread(target=run_weekly(parent), args=(1,)).start())
            weekly.grid(column=1, row=5, padx=10, pady=10)
            return weekly

        def run_weekly(parent):
            port = '25136'
            profile_id = '37c88147-8edc-48da-903b-ca0197b242d9'
     
            mla_url = 'http://' + str(self.domain) + ':' + str(
                port).strip() + '/api/v1/profile/start?automation=true&profileId=' + str(profile_id).strip()

            resp = requests.get(mla_url)
            jsn = resp.json()

            # #Define DesiredCapabilities
            opts = options.DesiredCapabilities()

            driver = webdriver.Remote(command_executor=jsn['value'], desired_capabilities={})

        # Add some labels to each tab
        for name in names:
            tab = nb.tabs[name]
            # create a StringVar for this tab

            weekly_label(tab)
            weekly_button(tab)

        return nb

    def create_menus(self):
        menu = tk.Menu(self, tearoff=False)
        self.config(menu=menu)
        subMenu = tk.Menu(menu, tearoff=False)
        menu.add_cascade(label="File", menu=subMenu)
        subMenu.add_separator()
        subMenu.add_command(label='Exit', command=self.destroy)
        return menu


class MyNotebook(ttk.Notebook):
    ''' A customised Notebook that remembers its tabs in a dictionary '''

    def __init__(self, master, names):
        super().__init__(master, width=390, height=470)

        # Create tabs & save them by name in a dictionary
        self.tabs = {}
        for name in names:
            self.tabs[name] = tab = ttk.Frame(self)
            self.add(tab, text=name)


GUI()
4

0 回答 0