从Python中的另一个函数调用函数中多个值的最佳方法

2024-04-20 11:24:40 发布

您现在位置:Python中文网/ 问答频道 /正文

当我最近使用pythonttkintergui和sqlite3构建一个项目时,我发现了Python编程中的许多问题。问题之一是从python中的另一个函数调用函数中的多个值的最佳方法是什么?同时,我对函数中的retunning和calling value做了一些研究,我知道在python函数中它可以返回多个值,但是,在调用时,我希望它具体地调用我返回的值,例如return (x,y,z),我真的不知道该如何调用它。在

这里有一些在我的项目中的代码,请随时给我任何关于我的代码和我在上面问的问题的建议

第一个功能

def taskUpdateB():
    conn = sqlite3.connect("zzzsqlite.db")
    booking = conn.cursor()

    index = sOLB.curselection()
    selTask = sOLB.get(index)
    bookinID = selTask[-2]

    getBookID = booking.execute('''SELECT bookingID FROM booking 
                        WHERE bookingID=?''', (bookinID,))    

    taUp = Toplevel()
    taUp.title("Task Update")
    taskLabel = Label(taUp, text ="Task Update", font=('Times', 20))
    taskLabel.grid(row=0)

    showLabel = Label(taUp, text ="Please Select and Enter Infomation Below", font=('Times', 18))
    showLabel.grid(row=1)

    var = IntVar()
    var = 0
    fullRadio = Radiobutton(taUp, text="Fully", variable=var, value=1, command = taskUpdCom)
    fullRadio.grid(row=2, sticky=W)

    partRadio = Radiobutton(taUp, text="Partly", variable=var, value=2, command = taskUpdCom)
    partRadio.grid(row=3, sticky=W)

    notRadio = Radiobutton(taUp, text="Unable", variable=var, value=3, command = taskUpdCom)
    notRadio.grid(row=4, sticky=W)

    noteLabel = Label(taUp, text ="Note:", font=('Times', 16))
    noteLabel.grid(row=5, sticky=W)
    noteBox = Text(taUp, width=30, height =20, font=('Arial', 12,), highlightbackground='black')
    noteBox.grid(row=6)

    comButton = Button(taUp, text ="Task Complete and Send Invoice", command = taskUpdCom)
    comButton.grid(row =7)

    booking.close()
    return (var, noteBox, showLabel, bookinID)

第二功能

^{pr2}$

请原谅我的代码还没有完全完成,有点乱。。。

感谢您的帮助:)


Tags: 函数代码texttaskvaluevarcommandgrid
1条回答
网友
1楼 · 发布于 2024-04-20 11:24:40

函数不是这样工作的。您可能希望调用函数,然后在调用范围中解压结果。在

var, noteBox, showLabel, bookinID = taskUpdateB()

虽然函数在Python中是对象,但它们不是有状态的处理器或其他东西,它们只是直接返回结果然后消失(除非你在做一些花哨的事情,但是你没有)。在

相关问题 更多 >