【问题标题】:How do I move the bottom label to the extreme right in Tkinter?如何在 Tkinter 中将底部标签移动到最右边?
【发布时间】:2020-11-05 18:01:00
【问题描述】:

这是我的代码 sn-p

footer_frame = tk.Frame()
tk.Label(footer_frame, text = 'by .....', font = 'arial 10', padx=5, pady=5).pack(side = tk.RIGHT, anchor='se')
footer_frame.pack(tk.BOTTOM)

【问题讨论】:

  • 您要移动整个标签,还是只移动标签的文本?你试过包装右边的标签吗?
  • @BryanOakley 怎么打包到右边?
  • 什么是?你的答案并不比问题更清楚。您希望实际标签 widget 位于右侧,还是希望小部件填充底部但 text 位于右侧?再说一次,如果你想把它放在右边,你试过把它装在右边吗?
  • 我想将标签小部件向右移动。而且我尝试使用 side=tk.RIGHT 将其打包到右侧,它不起作用
  • 这是因为你没有扩展页脚来填满所有的水平空间。

标签: python python-3.x tkinter tkinter-label


【解决方案1】:

要将标签一直放在页脚的右侧,最简单的方法是使用pack 并告诉它在右侧。

由于您没有将footer_frame 填充到底部,因此默认情况下它将居中。由于框架会缩小以适应其内容,因此标签也会居中显示。

这是一个示例,它使用side='right' 作为标签,fill='x' 作为页脚框架。我为标签赋予了独特的颜色,以便您可以看到它与窗户和框架的关系。

import tkinter as tk

root = tk.Tk()
root.geometry("400x200")
footer_frame = tk.Frame(root)
label = tk.Label(footer_frame, text="by .....", background="bisque")

footer_frame.pack(side="bottom", fill="x")
label.pack(side="right")

root.mainloop()

【讨论】:

  • 谢谢队友的帮助:)
猜你喜欢
  • 1970-01-01
  • 2021-01-03
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 2021-11-08
  • 2014-06-30
  • 1970-01-01
相关资源
最近更新 更多