0

Code objective: to get User data on click of Button using Tkinter and Code as follows:

class myClass:

    def OnClick():
        userData = entry.get()
        root.destroy()
        return userData

    def myFunction()
        <My code which creates GUI>
        button = Button (app, text="Submit", command=OnClick)
        button.grid()
        root.focus_set()
        root.mainloop()
        return userData


Object = myClass()
GetUserData = Object.myFunction()
print GetUserData

As user Enters a number on GUI and Clicks on Button, OnClick() function should return that value to myFunction() then it should return for GetUserData, but this code is not working as my objective.

WEshruth
  • 769
  • 3
  • 16
  • 32
  • your indentation is messed up. Can you please fix it? Is `useData` part of `myFunction1`? Is `OnClick` inside `myFunction1`? Also, are you destroying the root window on purpose? Do you intend to recreate it, or is this a temporary GUI you only use briefly while your program runs? – Bryan Oakley Oct 14 '13 at 17:31

1 Answers1

0

Got the solution for this, Had to declare userData as global, that made my solution.

WEshruth
  • 769
  • 3
  • 16
  • 32