このホームページは Amazon Kindle 本の作成中の草稿です。日々、原稿を見直しているので、内容が変わることに留意して読んで下さい。本が出版され次第、このホームページは削除されます。
4.13 ラベルフレーム表示位置とサイズ(1)(place_configure、place、x、y、width、height、place_info)
ラベルフレームの表示位置とサイズの設定はフレームと同じです。「3.10 フレーム表示位置とサイズ(1)」を参照して下さい。
次のプログラムは「place」メソッドでラベルフレームの表示位置とサイズを設定しています。設定後の値を「place_info」とメソッドで取得して「print」出力しています。全てのオプションに対する設定値を辞書型で、表示位置とサイズをそれぞれキーワードインデックスで取得して出力しています。
import tkinter as tk | |
root = tk.Tk() | |
root.geometry('300x200+100+100') | |
labelframe = tk.LabelFrame(root, bg='red', | |
text='labelframe', labelanchor='n') | |
labelframe.place(x=50, y=20, width=200, height=160) | |
print(labelframe.place_info()) | |
print('-----') | |
print('position', labelframe.place_info()['x'], | |
labelframe.place_info()['y']) | |
print('size', labelframe.place_info()['width'], | |
labelframe.place_info()['height']) | |
root.mainloop() |
「print」出力が各キーワードに対して下記のように得られます。
{'in': , 'x': '50', 'relx': '0', 'y': '20', 'rely': '0', 'width': '200', 'relwidth': '', 'height': '160', 'relheight': '', 'anchor': 'nw', 'bordermode': 'inside'}
-----
position 50 20
size 200 160
-----
position 50 20
size 200 160