python / tkinter挂起返回值的fom模块函数

时间:2020-10-07 22:54:35

标签: python tkinter

我有一个模块,我正在调用一个函数来返回凭据数据列表。该代码在普通的python3中工作,但是在tkinter中运行时,直到我关闭tkinter对话框之后,它才能获取值,然后按正常方式处理该函数的其余部分-除非我的程序已关闭。我已将所有内容追溯到dbconnect.py的返回。任何指针将不胜感激。谢谢! 编辑: 添加了login()函数。功能内的注释功能。从不实际退出login()。最后的输出来自子功能userinfo()。似乎停在那里,直到原始调用对话框关闭,然后成功完成主程序中的最后一个调用函数。

本地脚本调用:

import dbconnect

array = dbconnect.getcredentials()

dbconnect.py模块 dbconnect具有相关的功能,这些功能可以共同使用户登录并返回列表。

def getcredentials(): # call from other scripts for connection setup.
    credentials = []
    for item in sys.argv:
        credentials.append(item.strip("[,]"))
    credentials.pop(0)

    print("getcredentials(): items in argv after pop: ", credentials)

    if credentials:
        return(credentials)
    else:
        print("credentials not inialized!.def login():
# Create logwin window
logwin = Toplevel()
logwin.title("Log In")

# Called by login() GUI/bsubmit - returns credentials from log in GUI
def userinfo():
    global array
    # array = []
    sname=serventry.get()
    lname=lnentry.get()
    pname=passentry.get()
    array = [sname, lname, pname]
    logwin.destroy()
    print("userinfo() = ", array)
    return array

    # Called by login() GUI/ enter key from log in GUI
def userinfoalt(event): # event parameter is used to satisfy the the enter keybind
    global array
    # array = []
    sname=serventry.get()
    lname=lnentry.get()
    pname=passentry.get()
    array = [sname, lname, pname]
    logwin.destroy()
    print("userinfoalt() = ", array)
    return array


# Create GUI
servlabel = Label(logwin, text="Server Address: ")
servlabel.grid(row=0, column=0)
serventry = Entry(logwin)
serventry.grid(row=0, column=1)
serventry.focus()

lnlable = Label(logwin, text="User Name: ")
lnlable.grid(row=1, column=0, padx=5)
lnentry = Entry(logwin)
lnentry.grid(row=1, column=1, padx=4)

passlabel = Label(logwin, text="Enter Password: ")
passlabel.grid(row=2, column=0)
passentry = Entry(logwin, show="*")
passentry.grid(row=2, column=1)

bsubmit = Button(logwin, text="Submit", command=userinfo, default='active')
bsubmit.grid(row=4, column=1, columnspan=2)

logwin.bind('<Return>', userinfoalt) # binds alternate credentials function to the return key.
logwin.mainloop()
print("login() end:", array)
return(array)

正在登录...”) 凭证= login() 返回(凭证)

def login():
    # Create logwin window
    logwin = Toplevel()
    logwin.title("Log In")

    # Called by login() GUI/bsubmit - returns credentials from log in GUI
    def userinfo():
        global array
        # array = []
        sname=serventry.get()
        lname=lnentry.get()
        pname=passentry.get()
        array = [sname, lname, pname]
        logwin.destroy()
        print("userinfo() = ", array)
        return array

        # Called by login() GUI/ enter key from log in GUI
    def userinfoalt(event): # event parameter is used to satisfy the the enter keybind
        global array
        # array = []
        sname=serventry.get()
        lname=lnentry.get()
        pname=passentry.get()
        array = [sname, lname, pname]
        logwin.destroy()
        print("userinfoalt() = ", array)
        return array


    # Create GUI
    servlabel = Label(logwin, text="Server Address: ")
    servlabel.grid(row=0, column=0)
    serventry = Entry(logwin)
    serventry.grid(row=0, column=1)
    serventry.focus()

    lnlable = Label(logwin, text="User Name: ")
    lnlable.grid(row=1, column=0, padx=5)
    lnentry = Entry(logwin)
    lnentry.grid(row=1, column=1, padx=4)

    passlabel = Label(logwin, text="Enter Password: ")
    passlabel.grid(row=2, column=0)
    passentry = Entry(logwin, show="*")
    passentry.grid(row=2, column=1)

    bsubmit = Button(logwin, text="Submit", command=userinfo, default='active')
    bsubmit.grid(row=4, column=1, columnspan=2)

    logwin.bind('<Return>', userinfoalt) # binds alternate credentials function to the return key.
    logwin.mainloop()
    print("login() end:", array)
    return(array)

0 个答案:

没有答案