我正在编写一个脚本来自动填写表单,这需要手动花费大量时间。为此,我编写了一个脚本,该脚本通过启动 4 个不同的多登录配置文件来实现自动化。这里的问题是,每个驾驶员的车窗都与另一个车窗重叠。我想以如下所示的方式调整由这 4 个选项卡中的每一个启动的每个驱动程序窗口的大小/定位。
这是通过 tkinter 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, args=(parent,), daemon=True).start())
weekly.grid(column=1, row=5, padx=10, pady=10)
return weekly
def run_weekly(parent):
port = '54223'
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()
在这里经历了很多问题,但没有得到任何有效的答案。