Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top