Tkinter:从子窗口获取StringVar

时间:2017-02-11 22:52:33

标签: python tkinter

我对python / tkinter比较陌生,所以首先请原谅我凌乱的代码,希望你能理解它。我想在子窗口中获得用户输入的用户名(duh)以显示在父窗口中。但是,当我尝试使用带有.get方法的变量时,它表示尚未定义。任何帮助将不胜感激!

    #username window
def messageWindow():
    # create child window
    win = Toplevel()
    # display message
    message = "Set Username"
    Label(win, text=message).pack()
    global vv
    vv=StringVar()
    usr= Entry(win,textvariable =vv,width=30)
    vv.set("User")
    global ss
    ss = vv.get()
    usr.pack()
    print (ss)

    Button(win, text='OK', command=win.destroy).pack()
def callback(*args):
    f = open("htfl.txt","a")
    f.write((ss)+e.get()+"\n")
    e.delete(0, 'end')
    #print (e.get())

b = Button(master, text="Send", width=10, command=callback)

b.grid(row=10,column=2)

0 个答案:

没有答案