【发布时间】:2021-06-30 14:59:05
【问题描述】:
我希望在用户输入文本并点击 go 但标签未配置后将此标签配置到文本条目中。
我想要标有“你好!”的标签更改为放在主条目中的任何内容。我正在寻找用完整代码而不是固定行编写的答案。
这是我的代码:
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())
entry_frame = tk.Frame(root)
main_entry = tk.Entry(entry_frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(entry_frame, text= 'Go!', width=85, command= answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hello!").pack()
entry_frame.place(relx=.5, rely=.5, anchor='center')
root.mainloop()
【问题讨论】:
-
answer_label = tk.Label(text = "Hello!").pack()->answer_label = tk.Label(text = "Hello!") \n answer_label.pack()在两个不同的行中 -
另外,this 的回答已经有你的问题了。只有当你足够关注你才会得到答案。
-
@JacksonPro 他没有帮我解决我真正想要的问题,但在下面回答的人没有问题
-
好吧,我的错,但解决方案确实存在于那个答案中。此外,您不需要按照以下答案的建议传递标签。只需将其写成两行就足够了。
标签: python python-3.x tkinter pycharm