0

I am new to TKinter and I am not able to figure out how to store the input from a textbox in TKINTER. I've tried following virtually every tutorial and looked at similar posts but their ideas arent fixing my issue :/.

def cityInfoWindow(self, flightMap):
    infoWindow = Tk()
    infoWindow.geometry("500x500+100+100")
    infoWindow.title("CSAir-City Information")
    global input 
    input = StringVar()
    cityEntry = Entry(infoWindow,textvariable = input).pack()           
    okButton = Button(infoWindow, text = 'Submit', command = lambda:self.getCityInfo(infoWindow, input)).pack()

def getCityInfo(self, infoWindow, input):
    content = input.get()
    print content
    return

Ive tried passing in my input into my function but that doesnt work.

user2981811
  • 33
  • 1
  • 5

1 Answers1

4

There is built-in function named input, try not to use it as a variable name. Other than that, it is pretty straight-forward,

You assign a Variable Class of your choice (StringVar() in here) for Entry then get content of said variable any time you want with get() method.

Also there is a get() method for Entry. With that, you can get content of Entry without using StringVar.

Below is a simple example showing how to do it. You should implement it to your code yourself.

import tkinter as tk

def get_class():  #no need to pass arguments to functions in both cases
    print (var.get())

def get_entry(): 
    print (ent.get())


root = tk.Tk()

var = tk.StringVar()

ent = tk.Entry(root,textvariable = var)
btn1 = tk.Button(root, text="Variable Class", command=get_class)
btn2 = tk.Button(root, text="Get Method", command=get_entry)

ent.pack()
btn1.pack()
btn2.pack()

root.mainloop()

EDIT: By the way, next time when you post a question, please consider adding the full traceback or what went wrong (what did you expect and what did you get etc..) instead of saying "it is not working" only. With that, you will probably get more help with more precise answers.

Lafexlos
  • 7,618
  • 5
  • 38
  • 53