How to access variables from outside the interface

Viewed 47

I have an interface that asks for some inputs I want to access the inputs from the outside interface loop but can't figure out how he's what I have so far.

from tkinter import *


root = Tk()

s_n = Entry(root)
n_o_p = Entry(root)
s_t = Entry(root)
f_n = Entry(root)
c = Entry(root)

s_n.insert(0,"Enter Subreddit name")
n_o_p.insert(1,"Enter number of posts")
s_t.insert(2,"Enter search type")
f_n.insert(3,"Enter flair tpye")
c.insert(4,"Enter amount of comments")


s_n.pack()
n_o_p.pack()
s_t.pack()
f_n.pack()
c.pack()

def myclick():
    global s_n
    global n_o_p
    global s_t
    global f_n
    global c

myButton = Button(root, text="Enter: ", command=myclick)
myButton.pack()


root.mainloop()

#print (s_n)
#print (s_n.get())

I tried making the variables global but when I print the variable I just get !entry.

1 Answers

You can acces your variables with that code below:

from tkinter import *


root = Tk()

s_n = Entry(root)
n_o_p = Entry(root)
s_t = Entry(root)
f_n = Entry(root)
c = Entry(root)

s_n.insert(0,"Enter Subreddit name")
n_o_p.insert(1,"Enter number of posts")
s_t.insert(2,"Enter search type")
f_n.insert(3,"Enter flair tpye")
c.insert(4,"Enter amount of comments")


s_n.pack()
n_o_p.pack()
s_t.pack()
f_n.pack()
c.pack()


def myclick():
    global s_n
    s_n = s_n.get()


myButton = Button(root, text="Enter: ", command=myclick)
myButton.pack()

root.mainloop()


print(s_n)
Related