簡體   English   中英

如何在 Tkinter 的框架上更改文本 position

[英]How to I change text position on a frame in Tkinter

而是一個特定的請求,我似乎找不到任何在線文檔:

我正在嘗試更改按鈕周圍框架上字體的 position。 如下所示,文本當前位於按鈕上方的中心。 我希望文本顯示在按鈕的右側。

在此處輸入圖像描述

這是我的框架和按鈕代碼:

"""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)

任何建議或資源鏈接將不勝感激。

您可以使用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()

可能的值是基本方向 (NSEW) - tkinter 有這些常量

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM