📜  selenium python tkinter - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:15.653000             🧑  作者: Mango

代码示例1
import tkinter as tk
import selenium.webdriver

# --- functions ---

def on_open():
    global driver

    if not driver:
        driver = selenium.webdriver.Firefox()
        url = e.get()
        driver.get(url)

def on_close():
    global driver

    if driver:
        driver.close()
        driver = None

# --- main ---

driver = None

root  = tk.Tk()

e = tk.Entry(root)
e.pack()
e.insert('end', 'https://stackoverflow.com')

b = tk.Button(root, text='Selenium Open', command=on_open)
b.pack()

b = tk.Button(root, text='Selenium Close', command=on_close)
b.pack()

root.mainloop()