[英]How to I change text position on a frame in Tkinter
Rather a specific request I can't seem to find any online documentation on:而是一个特定的请求,我似乎找不到任何在线文档:
I'm trying to change the position of the font on frames surrounding buttons.我正在尝试更改按钮周围框架上字体的 position。 As shown below the text is currently centered above the button.
如下所示,文本当前位于按钮上方的中心。 I would like the text to be displayed to the right of the button.
我希望文本显示在按钮的右侧。
Heres my code for the frames and buttons:这是我的框架和按钮代码:
"""Button frames"""
constituent_frame = LabelFrame(root, text="Fibre and resin data inputs", padx=2, pady=2)
ply_frame = LabelFrame(root, text="Single lamina data inputs", padx=2, pady=2)
laminate_frame = LabelFrame(root, text="Complete ply stack data inputs", padx=2, pady=2)
"""Frame positions"""
constituent_frame.grid(row=2, column=1, padx=50)
ply_frame.grid(row=3, column=1, padx=50)
laminate_frame.grid(row=4, column=1, padx=50)
"""Button definitions"""
constituent_button = Button(constituent_frame, text='Constituent', width=15, command=click_constituent)
ply_button = Button(ply_frame, text='Ply', width=15, command=click_ply)
laminate_button = Button(laminate_frame, text='Laminate', width=15, command=click_laminate)
"""Button positions"""
constituent_button.grid(row=2, column=1, pady=2)
ply_button.grid(row=3, column=1, pady=2)
laminate_button.grid(row=4, column=1, pady=2)
Any advice or links to resources would be greatly appreciated.任何建议或资源链接将不胜感激。
You can use the labelanchor
argument on the LabelFrame
class to achieve this:您可以使用
labelanchor
上的LabelFrame
参数来实现此目的:
from tkinter import *
root = Tk()
labelframe = LabelFrame(root, text="Hello", labelanchor=E)
button = Button(labelframe, text="BUTTON")
labelframe.pack()
button.pack()
root.mainloop()
possible values are the cardinal directions (NSEW) - tkinter has constants for these可能的值是基本方向 (NSEW) - tkinter 有这些常量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.