【问题标题】:How to read a string from a file and set it as the text of a label in Python Tkinter? [duplicate]如何从文件中读取字符串并将其设置为 Python Tkinter 中的标签文本? [复制]
【发布时间】:2021-01-01 14:52:26
【问题描述】:

我一直试图将从文件中读取的字符串设置为小部件的文本,但是当我运行程序时它没有出现在窗口上。请帮助我并告诉我如何做到这一点。我已阅读该文件并将其保存在列表中。我想将列表元素设置为标签的文本。

【问题讨论】:

标签: python file tkinter label


【解决方案1】:
from tkinter import *

root = Tk()

f = open("C:\\Users\\Foo\\some_text.txt","r")
some_string = f.read()

my_label = Label(root, text=str(some_string)).pack()

root.mainloop()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2013-05-02
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多