【问题标题】:tkinter multiple variable return to different labelstkinter 多个变量返回不同的标签
【发布时间】:2015-07-28 10:39:44
【问题描述】:

恐怕这是一个“如何做”的问题。我有一个从文本文件返回三个变量的函数。我想将它们“打印”到单独的标签字段中,以便我可以清楚地突出显示不同的信息。到目前为止,我只设法使用 .format 表示法将它们组合成一个返回语句。所以我想

return date, name, numeric_data

并且希望能够在 tinter GUI 中

label_name.configure( text = date)
label_name2.configure( text = name)
label_name3.configure(text = numeric_data) 

目前,我只有:

        output = read_clean_format.openfile() # which is return "{}{}{}".format(text,text,text)
        version_result.configure(text = output)

这可能吗?我在哪里可以搜索信息。

【问题讨论】:

标签: python-3.x tkinter multiple-variable-return


【解决方案1】:

您不需要做任何特别的事情——让您的函数返回三个值,然后将这三个值与您的代码似乎显示的配置语句一起使用:

def openfile():
    ...
    return date, name, numeric_data

date, name, numeric_data = openfile()
label_name.configure(text=date)
label_name2.configure(text=name)
label_name3.configure(text=numeric_data)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 2018-10-04
    • 1970-01-01
    • 2014-09-14
    相关资源
    最近更新 更多