试图隐藏一个标签,但使用 python tkinter 单击按钮使其重新出现。小部件使用 .place 排列
trying to have a label hidden, yet have it reappear with a button click using python tkinter. The widgets are arranged using .place
这是我的代码片段。基本上,我有一个文本标签,我想在单击该按钮之前将其隐藏。按下按钮后,应出现标签。我可以让按钮 运行 具有其他功能,但不能将标签放回屏幕上。知道为什么这不起作用吗?
Mg_to_Use = Label(frame1, text = "The Mg needed for \
the above solution volume is:",
font = DialogFont, fg = "blue")
Mg_to_Use.place_forget(relx = .5, rely = .46, anchor = 'center')
myButton1 = Button(frame1, text = "Submit",
command = lambda: [Mg_to_Use.place(relx = .5, rely = .46, anchor = 'center'), Mg_calc(), MgToGrams(), Mg2Use()],
font = DialogFont, fg = "green")
myButton1.place(relx = .5, rely = .35, anchor = 'center')
如果不是一开始只单击按钮而是仅在按下按钮时才单击,为什么不只放置标签,这将不再需要,.place_forget()
。
尝试这样做:
from tkinter import *
root=Tk()
def f():
b.pack()
b=Label(root,text="last")
c=Button(root,text="prees",command=f)
c.pack()
root.mainloop()
这是我的代码片段。基本上,我有一个文本标签,我想在单击该按钮之前将其隐藏。按下按钮后,应出现标签。我可以让按钮 运行 具有其他功能,但不能将标签放回屏幕上。知道为什么这不起作用吗?
Mg_to_Use = Label(frame1, text = "The Mg needed for \
the above solution volume is:",
font = DialogFont, fg = "blue")
Mg_to_Use.place_forget(relx = .5, rely = .46, anchor = 'center')
myButton1 = Button(frame1, text = "Submit",
command = lambda: [Mg_to_Use.place(relx = .5, rely = .46, anchor = 'center'), Mg_calc(), MgToGrams(), Mg2Use()],
font = DialogFont, fg = "green")
myButton1.place(relx = .5, rely = .35, anchor = 'center')
如果不是一开始只单击按钮而是仅在按下按钮时才单击,为什么不只放置标签,这将不再需要,.place_forget()
。
尝试这样做:
from tkinter import *
root=Tk()
def f():
b.pack()
b=Label(root,text="last")
c=Button(root,text="prees",command=f)
c.pack()
root.mainloop()