2017-12-17 4 views
0

テキストに関係なくすべてのtkinterボタンを同じサイズにしたい。他のボタンを伸ばしてお互いに合わせたり、特定のサイズを設定することは可能ですか?私はドキュメントの中でそうする方法を見つけるのが難しいです。現在、ボタンはテキストのサイズに基づいて伸縮します。 Example of what I mean。それらをすべて同じサイズにすることは可能ですか?tkinterボタンのサイズを同じにする

答えて

1

通常、ジオメトリマネージャ(pack,place、またはgrid)を使用するときにこれを実行します。

使用グリッド:パックを使用して

import tkinter as tk 

root = tk.Tk() 
for row, text in enumerate((
     "Hello", "short", "All the buttons are not the same size", 
     "Options", "Test2", "ABC", "This button is so much larger")): 
    button = tk.Button(root, text=text) 
    button.grid(row=row, column=0, sticky="ew") 

root.mainloop() 

は:

import tkinter as tk 

root = tk.Tk() 
for text in (
     "Hello", "short", "All the buttons are not the same size", 
     "Options", "Test2", "ABC", "This button is so much larger"): 
    button = tk.Button(root, text=text) 
    button.pack(side="top", fill="x") 

root.mainloop() 
+0

このアプローチでは、ボタンが含まウィジェットは、最大幅のボタンの同じ幅を持っているだろうという事実を利用します。コンテナの幅に合わせてすべてのボタンを展開します。 – Nae

関連する問題