0

I've been looking all over the internet for a way to store and call back a Tkinter user input as a variable (in Selenium). I've read about Pickle and JSON dumps but nothing seems to work.

top = Tk()
L1 = Label(top, text="Auto-Connect",).grid(row=0,column=1)
L2 = Label(top, text="EMAIL",).grid(row=1,column=0)
L3 = Label(top, text="PASSWORD",).grid(row=2,column=0)
L4 = Label(top, text="URL",).grid(row=3,column=0)

E1 = Entry(top, bd =5)
E1.grid(row=1,column=1)

E2 = Entry(top, bd =5)
E2.grid(row=2,column=1)

E3 = Entry(top, bd =5)
E3.grid(row=3,column=1)

All I'm trying to do is set variables in a Selenium script from the user interface. If this has been asked before I apologize... I promise I've spent all day looking.

Chris Brocious
  • 161
  • 1
  • 3
  • 13

1 Answers1

2

I assume you want to get the input from the entry widget and use it in your selenium script. This is infact very simple to do.

Below i have created a mini ui which will do this

CODE:

from tkinter import *

def storeVar():
    AutoConnect = E1.get()
    Email = E2.get()
    Password = E3.get()
    Url = E4.get()

    global variables
    variables = [AutoConnect, Email, Password, Url]

root = Tk()

L1 = Label(root, text="Auto-Connect",).grid(row=0,column=0)
L2 = Label(root, text="EMAIL",).grid(row=1,column=0)
L3 = Label(root, text="PASSWORD",).grid(row=2,column=0)
L4 = Label(root, text="URL",).grid(row=3,column=0)

E1 = Entry(root, bd =5)
E1.grid(row=0,column=1)

E2 = Entry(root, bd =5)
E2.grid(row=1,column=1)

E3 = Entry(root, bd =5)
E3.grid(row=2,column=1)

E4 = Entry(root, bd =5)
E4.grid(row=3,column=1)

submit = Button(root, text= "Submit", command = storeVar)
submit.grid(row=4)

root.mainloop()

Here is a screen shot: UI screenshot

Now to access these variables in your selenium script you have to import the list containing the variables so in the case of my example:

say i saved the code above in a script called ui.py in the selenium script i would write:

from ui import variables
print(variables)

variables being the list containing the varibales to be used

feel free to ask me anything you dont understand.

Moller Rodrigues
  • 780
  • 5
  • 16
  • I believe this is what OP was trying to do, he really needs to update the question to be more specific. – james-see Feb 10 '18 at 02:08
  • Thank you Moller. I appreciate people helping nubes out, since everyone else wants to troll. I’ll check it out. Hopefully it works, and you’ll get all the praise. ... I’ve never used a GUI before. – Chris Brocious Feb 10 '18 at 03:20
  • Np m8 don't forget in my example I saved all the variables in a list and imported the list to the other script so if u want to access those variable you have to index the list just in case u missed that – Moller Rodrigues Feb 10 '18 at 03:26
  • @ChrisBrocious Who exactly wants to troll? Do you have a passion for being ambiguous or rather enjoy wasting people's time? – Nae Feb 10 '18 at 13:04
  • @MollerRodrigues. This was exactly what I'm looking for. I'm getting an import error though: ImportError: cannot import name 'variables' – Chris Brocious Feb 11 '18 at 19:43
  • @ChrisBrocious what is the error that you are getting – Moller Rodrigues Feb 11 '18 at 19:44
  • @MollerRodrigues ImportError: cannot import name 'variables' – Chris Brocious Feb 11 '18 at 20:12
  • @ChrisBrocious hey dude so just above before you assign variables you have to make it global (global variables) that should fix it then in the selenium script write from ui import variable and then you can use variables however you would like – Moller Rodrigues Feb 11 '18 at 20:36
  • i hav updated the code i just tested it and its working – Moller Rodrigues Feb 11 '18 at 20:39
  • @MollerRodrigues pure genius!! Thank you *1,000,000^Nth pwr. – Chris Brocious Feb 11 '18 at 21:44