0

In my program I have a tkinter Entry widget named keyE. The user enters a "product" key here. Later, I try to retrieve the users input using the .get() feature, and save it to a variable, key_input, like this: key_input=keyE.get(), however, I never can seem to get a value. PyScripter keeps showing that no value is ever assigned to key_input. Doing some research, people seem to add (END, "1.0" to the parameters for get, but in doing to I get an error saying there are too many parameters, even if i add just a single parameter. Any thoughts or ideas? The entire class its part of is shown below. Not sure if its all relevant, but perhaps somewhat useful. Lines I thought were most relevant are commented.

class PageOne(tk.Frame):
def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)

    actTotalFrame =tk.Frame(self)

    topBarAct = Frame(actTotalFrame)
    softLogo = Label(topBarAct,image=softLogoRaw)
    versionNum = Label(topBarAct,image=versionNumRaw)

    ActivateT=Text(actTotalFrame, width=45,height=5)
    keyE= tk.Entry(actTotalFrame)    #entry box here
    submitButton=Button(actTotalFrame, text = "Submit",command= lambda: controller.show_frame(PageThree), width = 40)
    returnButton=Button(actTotalFrame, text = "Return",command= lambda: controller.show_frame(StartPage), width = 40)
    global statusB
    statusB =Label(actTotalFrame, text="Waiting for user input", bd=1, relief=SUNKEN, anchor=W)

    softLogo.pack(side =LEFT)
    versionNum.pack(side=RIGHT)

    ActivateT.insert(END, "In order to use all the features included\nin this program, especially all the ones\nthat arent useful anyways, you need to have\nspent the money to buy the 'Paid version'. If\nyou did that, you can enter the key below: ")


    topBarAct.pack(side=TOP)
    ActivateT.pack(side=TOP,padx=5,pady=5)
    keyE.pack()
    global key_input
    key_input=keyE.get()#trying to read the value here, to another variable named key_input, but this always remains null
    submitButton.pack()
    returnButton.pack()

    statusB.pack (side=BOTTOM, fill=X)
    actTotalFrame.pack()
qwerty22
  • 101
  • 2
  • 6
  • It looks like `keyE` can never have any text when you use `keyE.get()`. so it returns an empty string, which is what it's supposed to return. Also, you should probably not use globals, they prevent code abstractions and are generally considered bad. – Reut Sharabani Jan 24 '15 at 22:53
  • Okay, *why* can it not have any text, and how can it have text? And I need that global for another part of the program, which isnt really relevant to this bit so I wont go into detail – qwerty22 Jan 24 '15 at 22:59
  • It seems as though it is indeed a duplicate, my error, sorry. Just going to try to implement the solution proposed in that answer, adn if Im sucessful, Ill remove this. – qwerty22 Jan 24 '15 at 23:17
  • when does it get input? – Reut Sharabani Jan 24 '15 at 23:50
  • Problem is this, as I found in the other question, the issue comes from me not having packed the entry box before I try to read from it. This however is impossible, because both the button and the entry box need to be packed into the smae master fram and are therefore ultimately placed at the same time, and theres no way for the user to enter the text before the button and read functions are placed. I cant think of a way around this, as everything *must* be in the same master frame. I guess Ill be removing this function from the program unless someoone can think of a way around this. – qwerty22 Jan 25 '15 at 00:06
  • The main question is actually why are you reading text immediatly from an empty entry widget? – Reut Sharabani Jan 25 '15 at 00:18
  • are you suggesting a way to fix this? – qwerty22 Jan 25 '15 at 00:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69531/discussion-between-reut-sharabani-and-qwerty22). – Reut Sharabani Jan 25 '15 at 00:43

0 Answers0