Label textvariable空Python 3.6 OSX

2024-10-02 14:28:22 发布

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

我在使用label.config(textvariable=texto)时遇到问题。 因此,texto StringVar()似乎为空,因为没有显示“textovable”

import tkinter as tk 
root = tk.Tk() 
texto = tk.StringVar(value='Texto inicial')
texto.set(value='TextoVariable')

tk.Label(root, text='Hola Mundo').pack(anchor='nw') 

label = tk.Label(root)
label.pack(anchor='center')

tk.Label(root, text='Hola Saturno').pack(anchor='se')

label.config(bg='green', fg='blue', font=('Verdana',24))
label.config(textvariable=texto)

root.mainloop() 

Tags: textimportconfigvaluerootlabelpacktk