python tkinter return value from function used in command

前端 未结 5 473
遇见更好的自我
遇见更好的自我 2020-12-16 01:22

how do i get the return value A to C? I am not using class by the way.

def button:
    mylabel = Label(myGui, text = \"hi\").grid(row = 0, column = 0)
    A          


        
5条回答
  •  离开以前
    2020-12-16 01:31

    it's easy just declare A a global.

    def button:
    global A
    mylabel = Label(myGui, text = "hi").grid(row = 0, column = 0)
    A = B.get()
    return A
    
    B = StringVar()`
    C = ""
    myentry = Entry(myGui, textvariable = B).grid(row = 1, column = 0)
    Submit = Button(myGui, text = "Submit", command = button).grid(row = 1, column = 1)
    # and then A is not empty
    B= A
    

提交回复
热议问题