dimanche 30 juin 2019

Why can I not use checkboxes when using tkinter?

I am trying to grab a list from a website, assign each option to a checkbox, and allow the user to select an option. When i run the code however, the window pops up, but I am unable to select an option. When i try to check the box, it does not allow me to.

Here is the portion of my code that is causing issues.

            select_element = Select(driver.find_element_by_css_selector("#songID"))
            select_song.config(background="deep sky blue")
            select_song.title('Select Song')
            song_label = Label(select_song, text="Please select the song you would like to promote")
            song_label.config(background="deep sky blue", foreground="white")
            song_label.grid(row=0)
            rowId = 1
            var = IntVar()
            songList = [o.text for o in select_element.options]
            optionList=[]

            for song in songList:
                check = Checkbutton(select_song, text=song, variable=var, bg="deep sky blue", fg="white").grid(row=rowId)

                rowId = rowId + 1
            select_song.mainloop()
            optionList.append([song,var])

I haven't had this issue before and I'm not sure what is causing it.

Here is my full code:

from Tkinter import *
from PIL import ImageTk,Image
import time
from datetime import tzinfo
from selenium.webdriver.support.ui import Select


def main():

    chromedriver = "C:\Users\Alex\Desktop\chromedriver"
    driver = webdriver.Chrome(chromedriver)
    driver.get("https://www.soundclick.com/community/SC4/login.cfm")

    def songOptions():
        print (song,var.get())


    def start():
        my_window.mainloop()

    def prepare():
        email = email_text.get()
        password = pass_text.get()
        my_window.destroy()
        xpathEmail = '//*[@id="email"]'
        loginEmail = driver.find_element_by_xpath(xpathEmail)
        loginEmail.send_keys(email)
        xpathPass = '//*[@id="password"]'
        loginPass = driver.find_element_by_xpath(xpathPass)
        loginPass.send_keys(password)
        xpathLogin = '//*[@id="loginform"]/div[3]/div[2]/input'
        login = driver.find_element_by_xpath(xpathLogin)
        login.click()
        time.sleep(2)

        if driver.current_url == "https://www.soundclick.com/bandAdmin2/default.cfm?ipv=0":
            xpathEdit = '//*[@id="mySCTab_content"]/div/div[2]/div[2]/a[1]'
            edit = driver.find_element_by_xpath(xpathEdit)
            edit.click()
            time.sleep(2)

            xpathClose = '/html/body/div[9]/div/div/a'
            close = driver.find_element_by_xpath(xpathClose)
            close.click()
            time.sleep(2)

            xpathPromote = '//*[@id="mySCTab"]/li[6]/a'
            promote = driver.find_element_by_xpath(xpathPromote)
            promote.click()

            xpathSOD = '//*[@id="mySCTab_content"]/ul/li[3]/a'
            SOD = driver.find_element_by_xpath(xpathSOD)
            SOD.click()


            select_song=Tk()
            select_element = Select(driver.find_element_by_css_selector("#songID"))
            select_song.config(background="deep sky blue")
            select_song.title('Select Song')
            song_label = Label(select_song, text="Please select the song you would like to promote")
            song_label.config(background="deep sky blue", foreground="white")
            song_label.grid(row=0)
            rowId = 1
            var = IntVar()
            songList = [o.text for o in select_element.options]
            optionList=[]

            for song in songList:
                check = Checkbutton(select_song, text=song, variable=var, bg="deep sky blue", fg="white").grid(row=rowId)

                rowId = rowId + 1
            select_song.mainloop()
            optionList.append([song,var])


        elif driver.current_url == "https://www.soundclick.com/community/SC4/loginRegAuth.cfm":
            driver.close()
            main()



    my_window=Tk()

    my_window.title('SoundClick Login')

    my_window.configure(background="deep sky blue")

    email_label=Label(my_window, text="Please Enter The Email Used To Sign Into SoundClick")
    email_label.config(background="deep sky blue", foreground="white")

    email_text = Entry(my_window)
    email_text.pack()
    pass_label=Label(my_window, text="Please Enter The Password Used To Sign Into SoundClick")
    pass_label.config(background="deep sky blue", foreground="white")
    pass_text=Entry(my_window)
    pass_text.pack()



    pass_text.config(show="*")
    song_text = Entry(my_window)
    song_label=Label(my_window, text="Please Enter The Name Of The Song You Want To Promote. Warning:cAsE SensItIvE")
    song_label.config(background="deep sky blue", foreground="white")

    finish_button = Button(my_window, text="Done",command=prepare)
    finish_button.config(background="white")
    note_label=Label(my_window, text="This information will not be stored anywhere")
    note_label.config(background="deep sky blue", foreground="white")


    email_label.grid(row=0, column=0)
    email_text.grid(row=0, column=1)
    pass_label.grid(row=1, column=0)
    pass_text.grid(row=1, column=1)
    finish_button.grid(row=3, column=0)

    start()
main()




Aucun commentaire:

Enregistrer un commentaire