Tkinter崩溃并且不允许我打开.py文件

时间:2019-03-09 19:20:18

标签: python selenium tkinter selenium-chromedriver

这是程序代码

from tkinter import *
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import time

screen = Tk()
screen.geometry("600x450")
screen.title("Super Bot")
screen.configure(background = "grey")



def web():
        name = nameentry.get()
        email = emailentry.get()
        telephone = telentry.get()
        address = adrentry.get()
        zipad = zipentry.get()
        city = cityentry.get()
        state = stateentry.get()
        number = numberentry.get()
        datem = expentry1.get()
        datey = expentry2.get()
        cvv = cvventry.get()
        category.get()
        size.get()
        keyword.get()
        color = colorentry.get()



        driver = webdriver.Chrome(executable_path=r'C:\Users\artjo\Desktop\Python\chrome\chromedriver.exe')
        driver.get('https://www.supremenewyork.com/shop/all/{}'.format(category.get()))

        while True:
         try:
              driver.find_element_by_partial_link_text(keyword.get())
              break
         except (NoSuchElementException):
              wait=WebDriverWait(driver, 10)
              waitBis=wait.until(EC.presence_of_element_located((By.ID, 'time-zone-name')))
              driver.refresh()

        wait=WebDriverWait(driver, 10)

        driver.find_element_by_partial_link_text(keyword.get()).click()

我在这里占了很大一部分,因为,我不想让任何人复制它,而只需要用户在那里链接链接并按下按钮。这是发生的一切的一幕-Youtube Video of Example

        ord_cnb=driver.find_element_by_id('nnaerb')
        ord_cnb.send_keys(number)
        Select(driver.find_element_by_id('credit_card_month')).select_by_visible_text(datem)
        Select(driver.find_element_by_id('credit_card_year')).select_by_visible_text(datey)



name = str
email = str
telephone = str
address = str
zipad = str
city = str
state = str
number = str
datem = str
datey = str
cvv = str
category = StringVar()
size = StringVar()
keyword = StringVar()
color = str


namelabel = Label(screen, width = 10, text = "name", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
namelabel.place(x = 30, y = 62)
nameentry = Entry(screen, textvariable = name, width = 20, bg = "white")
nameentry.place(x = 130, y = 64)

emaillabel = Label(screen, width = 10, text = "e-mail", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
emaillabel.place(x = 30, y = 102)
emailentry = Entry(screen, textvariable = email, width = 20, bg = "white")
emailentry.place(x = 130, y = 104)

tellabel = Label(screen, width = 10, text = "telephone", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
tellabel.place(x = 30, y = 142)
telentry = Entry(screen, textvariable = telephone, width = 20, bg = "white")
telentry.place(x = 130, y = 144)

adrlabel = Label(screen, width = 10, text = "address", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
adrlabel.place(x = 30, y = 182)
adrentry = Entry(screen, textvariable = address, width = 20, bg = "white")
adrentry.place(x = 130, y = 184)

ziplabel = Label(screen, width = 10, text = "zip", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
ziplabel.place(x = 30, y = 222)
zipentry = Entry(screen, textvariable = zipad, width = 20, bg = "white")
zipentry.place(x = 130, y = 224)

citylabel = Label(screen, width = 10, text = "city", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
citylabel.place(x = 30, y = 262)
cityentry = Entry(screen, textvariable = city, width = 20, bg = "white")
cityentry.place(x = 130, y = 264)

statelabel = Label(screen, width = 10, text = "state", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
statelabel.place(x = 30, y = 302)
stateentry = Entry(screen, textvariable = state, width = 20, bg = "white")
stateentry.place(x = 130, y = 304)

numberlabel = Label(screen, width = 10, text = "number", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
numberlabel.place(x = 320, y = 62)
numberentry = Entry(screen, textvariable = number, width = 20, bg = "white")
numberentry.place(x = 420, y = 64)

explabel = Label(screen, width = 10, text = "exp. date", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
explabel.place(x = 320, y = 102)
expentry1 = Entry(screen, textvariable = datem, width = 5, bg = "white")
expentry1.place(x = 420, y = 104)
expentry2 = Entry(screen, textvariable = datey, width = 8, bg = "white")
expentry2.place(x = 470, y = 104)

cvvlabel = Label(screen, width = 10, text = "cvv", bg = "white", fg = "black", font = ("Courier", 10), anchor = W)
cvvlabel.place(x = 320, y = 142)
cvventry = Entry(screen, textvariable = cvv, width = 5, bg = "white")
cvventry.place(x = 420, y = 144)

keywordlabel = Label(screen, width = 10, text = "keyword", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
keywordlabel.place(x = 320, y = 222)
keywordentry = Entry(screen, textvariable = keyword, width = 20, bg = "orange")
keywordentry.place(x = 420, y = 224)

colorlabel = Label(screen, width = 10, text = "color", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
colorlabel.place(x = 320, y = 262)
colorentry = Entry(screen, textvariable = color, width = 20, bg = "orange")
colorentry.place(x = 420, y = 264)

sizelabel = Label(screen, width = 10, text = "size", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
sizelabel.place(x = 320, y = 300)
sizelist = ["Small", "Medium", "Large","XLarge"]
size.set(sizelist[0])
sizemenu = OptionMenu(screen, size, *sizelist)
sizemenu.configure(font = ("Courier", 10),bg = "orange")
sizemenu.place(x = 415, y = 302)

categorylabel = Label(screen, width = 10, text = "category", bg = "orange", fg = "black", font = ("Courier", 10), anchor = W)
categorylabel.place(x = 320, y = 182)
categorylist = ["jackets", "shirts", "tops_sweaters","sweatshirts", "pants", "shorts", "t-shirts", "hats", "bags", "accessories", "skate", "shoes"]
category.set(categorylist[0])
categorymenu = OptionMenu(screen, category, *categorylist)
categorymenu.configure(font = ("Courier", 9),bg = "orange")
categorymenu.place(x = 415, y = 184)

button1 = Button(screen, text="START", command=web)
button1.configure(font = ("Courier", 12), bg = "green", width = 10, height = 2)
button1.place(x=480,y=360)

screen.mainloop()

因此,最后我有了屏幕的主循环,但是当我转到python文件并单击此.py文件时,它将弹出控制台并立即关闭,而无需打开GUI(请参见上面的视频)。可能是什么问题。有什么建议吗?

0 个答案:

没有答案