第 4 章 ラベルフレーム

◀ 4.12 ラベルの置き換え   【目  次】  4.14 ラベルフレーム表示位置とサイズ(2) ▶

999999

 更新日:


 このホームページは Amazon Kindle 本の作成中の草稿です。日々、原稿を見直しているので、内容が変わることに留意して読んで下さい。本が出版され次第、このホームページは削除されます。

4.13 ラベルフレーム表示位置とサイズ(1)(place_configure、place、x、y、width、height、place_info)

ラベルフレームの表示位置とサイズの設定はフレームと同じです。「3.10 フレーム表示位置とサイズ(1)」を参照して下さい。


次のプログラムは「place」メソッドでラベルフレームの表示位置とサイズを設定しています。設定後の値を「place_info」とメソッドで取得して「print」出力しています。全てのオプションに対する設定値を辞書型で、表示位置とサイズをそれぞれキーワードインデックスで取得して出力しています。

1
import tkinter as tk
2
root = tk.Tk()
3
root.geometry('300x200+100+100')
4
labelframe = tk.LabelFrame(root, bg='red',
5
        text='labelframe', labelanchor='n')
6
labelframe.place(x=50, y=20, width=200, height=160)
7
print(labelframe.place_info())
8
print('-----')
9
print('position', labelframe.place_info()['x'],
10
        labelframe.place_info()['y'])
11
print('size', labelframe.place_info()['width'],
12
        labelframe.place_info()['height'])
13
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