문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top