Python 当我使用tkinter配置选项时,为什么这个标签没有改变

Python 当我使用tkinter配置选项时,为什么这个标签没有改变,python,user-interface,tkinter,pycharm,widget,Python,User Interface,Tkinter,Pycharm,Widget,我想更改这个标签,所以我使用了widget.config选项,但由于某些原因它不起作用。这是我的密码: import tkinter as tk root = tk.Tk() root.attributes('-fullscreen', True) exit_button = tk.Button(root, text="Exit", command = root.destroy) exit_button.place(x=1506, y=0) def answer()

我想更改这个标签,所以我使用了widget.config选项,但由于某些原因它不起作用。这是我的密码:

import tkinter as tk

root = tk.Tk()
root.attributes('-fullscreen', True)


exit_button = tk.Button(root, text="Exit", command = root.destroy)
exit_button.place(x=1506, y=0)


def answer():
    global main_entry
    answer_label.config(main_entry)

frame = tk.Frame(root)
main_entry = tk.Entry(frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(frame, text='Go!', width=85, command = answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hey").pack()
frame.place(relx=.5, rely=.5, anchor='center')

root.mainloop()

这个代码有效。它配置标签以更改文本。我不知道您试图通过configmain\u条目实现什么

import tkinter as tk

root = tk.Tk()
root.attributes('-fullscreen', True)


exit_button = tk.Button(root, text="Exit", command = root.destroy)
exit_button.place(x=1506, y=0)


def answer():
    global main_entry, answer_label
    answer_label.config(text="hi")

frame = tk.Frame(root)
main_entry = tk.Entry(frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(frame, text='Go!', width=85, command = answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hey")
answer_label.pack()
frame.place(relx=.5, rely=.5, anchor='center')

root.mainloop()

在使用config函数时,您必须提及要更改的内容。 尝试:- answer\u label.configtext=要显示的文本

此外,您还没有从条目小部件获取值:为此,您可以使用: 应答\u label.configtext=main\u entry.get

完整代码如下所示:

import tkinter as tk

root = tk.Tk()
root.attributes('-fullscreen', True)


exit_button = tk.Button(root, text="Exit", command = root.destroy)
exit_button.place(x=1506, y=0)


def answer():
    answer_label.config(text=main_entry.get())

frame = tk.Frame(root)
main_entry = tk.Entry(frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(frame, text='Go!', width=85, command = answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hey")
answer_label.pack()
frame.place(relx=.5, rely=.5, anchor='center')

root.mainloop()

你在这里没有错,你可以消除你答案中的不确定性。另外,请注意删除global,因为它在那里是无用的。感谢您为我指明了正确的方向。您能告诉我在我的完整代码plz中会是什么样子吗?现在查看它。我已经更新了解决方案。