【问题标题】:Python - Button with imported functionPython - 具有导入功能的按钮
【发布时间】:2018-12-05 12:06:17
【问题描述】:

我有一个问题:按钮命令在我运行脚本时被执行。

我一直在寻找问题,但我无法弄清楚。

如果你能帮助我,我会很高兴。

from tkinter import *
from tkinter import ttk
from config import *
import prueba_browser as pb

#Ejecuta la función del archivo prueba_browser
bok=ttk.Button(miFrame, text="execute", command=pb.openbrowser)
bok.grid(row=2, column=1)

这是保存openbrowser函数的文件

from selenium import webdriver
from selenium.webdriver.common.by import By
import config as c   

def openbrowser():

    browser= webdriver.Chrome(executable_path=c.path)
    browser.get("https://www.darkorbit.es")

    login_form = browser.find_element_by_id('bgcdw_login_form_username')
    password_form = browser.find_element_by_id('bgcdw_login_form_password')
    boton_continuar = browser.find_element_by_xpath("//fieldset[@class='bgcdw_login_form_buttons']/input[1]")

    login_form.send_keys(c.usuario)
    password_form.send_keys(c.passwd)
    boton_continuar.click()

openbrowser()

【问题讨论】:

  • 问题是:为什么我运行脚本时会执行按钮命令

标签: python function button tkinter import


【解决方案1】:

您正在调用定义它的文件中的函数(底部的openbrowser())。

删除此通话。

【讨论】:

  • 工作。非常感谢
猜你喜欢
  • 2014-08-16
  • 2011-12-12
  • 2011-10-17
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-03
相关资源
最近更新 更多