【发布时间】:2023-03-21 15:03:02
【问题描述】:
def func(list,n):
if n==1:
text=round(kcal_measure(sport.get(),now[0],time.get()),1)
list.append(text)
Label(newWindow,text=sport.get()+"KCAL: "+str(text)+"kcal").place(x=60,y=132)
time.delete(0,END)
if n==2:
Label(newWindow,text="Total KCAL: "+str(sum(list))+"kcal").pack()
Button(newWindow,text="add",command=lambda:func(k,1)).place(x=105,y=105)
Button(newWindow,text="ok",command=lambda:func(k,2)).place(x=155,y=105)
def func(list,n):
if n==1:
text=round(kcal_measure(sport.get(),now[0],time.get()),1)
list.append(text)
Label(newWindow,text=sport.get()+"KCAL: "+str(text)+"kcal").pack()
time.delete(0,END)
if n==2:
Label(newWindow,text="Total KCAL: "+str(sum(list))+"kcal").pack()
Button(newWindow,text="add",command=lambda:func(k,1)).place(x=105,y=105)
Button(newWindow,text="ok",command=lambda:func(k,2)).place(x=155,y=105)
我希望标签不与按钮重叠。 首先,我使用 .place()。但是这种方法在标签之间重叠。 接下来,我使用 .pack()。但是这个方法在标签之间不重叠,而是和按钮重叠。
标签和按钮如何摆放整齐?
【问题讨论】:
-
您不应在同一框架/窗口中同时使用
.pack和.place。只坚持其中之一。我更喜欢使用.pack -
@TheLizzard 但是,在使用
.pack时,按钮不是放在两边,而是上下放置。 -
您知道可以传入
side=...参数,该参数可以是以下之一:"top"、"bottom"、"left"、"right" -
@hyem_msg 您可以将按钮放在框架中。然后您可以在您的案例中的所有小部件上使用
.pack()。 -
@acw1668 我可以使用框架解决这个问题。谢谢。
标签: python tkinter button label overlap