Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top