前提
Windows10、python 3.8 で tkinterを使ってGUIを作っているのですが、なにが原因でstickyが効いていないのかわかりません。
gridを使ってボタンを配置してます。
実現したいこと
- ウィンドウサイズを変化させたときに、ボタンもそれに合わせて大きさを変化させたい
- ウィンドウの大きさと同じ(隙間なく)ボタンを配置したい
- (できればボタンの大きさも統一したい)
発生している問題・エラーメッセージ
画像の下側、右側の灰色(白?)のところがうまくいっていない部分です。
どれだけ動かしても左端だけはしっかりとくっついています。
該当のソースコード
python
1import tkinter as tk 2 3# color 4DARK_GRAY = ('#202020') 5LIGHT_GRAY = ('#343434') 6ORANGE = ('#ff9f0a') 7SMOKE_WHITE = ('#a5a5a5') 8WHITE = ('#ffffff') 9BLACK = ('#000000') 10 11class Calclator(tk.Frame): 12 13 def __init__(self, master=None): 14 super().__init__(master) 15 self.create_widgets() 16 17 def create_widgets(self): 18 19 # rayout 20 button_layout = ( 21 # row, col, label, func, color 22 (1, 0, 'MC', self.MC, DARK_GRAY), 23 (1, 1, 'MR', self.MR, DARK_GRAY), 24 (1, 2, 'CE', self.CE, SMOKE_WHITE), 25 (1, 3, '±', self.plu_sub, SMOKE_WHITE), 26 (1, 4, '%', self.percent, SMOKE_WHITE), 27 (1, 5, '÷', self.div, ORANGE), 28 (2, 0, 'MS', self.MS, DARK_GRAY), 29 (2, 1, 'C', self.clear, DARK_GRAY), 30 (2, 2, '7', self.numinput, LIGHT_GRAY), 31 (2, 3, '8', self.numinput, LIGHT_GRAY), 32 (2, 4, '9', self.numinput, LIGHT_GRAY), 33 (2, 5, '×', self.mul, ORANGE), 34 (3, 0, 'M+', self.M_plus, DARK_GRAY), 35 (3, 1, 'M-', self.M_sub, DARK_GRAY), 36 (3, 2, '4', self.numinput, LIGHT_GRAY), 37 (3, 3, '5', self.numinput, LIGHT_GRAY), 38 (3, 4, '6', self.numinput, LIGHT_GRAY), 39 (3, 5, '-', self.sub, ORANGE), 40 (4, 0, '税込', self.in_tax, DARK_GRAY), 41 (4, 1, '税抜', self.out_tax, DARK_GRAY), 42 (4, 2, '1', self.numinput, LIGHT_GRAY), 43 (4, 3, '2', self.numinput, LIGHT_GRAY), 44 (4, 4, '3', self.numinput, LIGHT_GRAY), 45 (4, 5, '+', self.add, ORANGE), 46 (5, 0, '√', self.root, DARK_GRAY), 47 (5, 1, '!', self.fact, DARK_GRAY), 48 (5, 2, '0', self.numinput, LIGHT_GRAY), 49 (5, 3, '00', self.numinput, LIGHT_GRAY), 50 (5, 4, '.', self.point, LIGHT_GRAY), 51 (5, 5, '=', self.equal, ORANGE) 52 ) 53 54 # create buttons 55 for row, col, label, func, color in button_layout: 56 if color == DARK_GRAY: 57 button = tk.Button(self, text=label, font=('MSゴシック', 15), bg=DARK_GRAY, foreground=WHITE) 58 elif color == LIGHT_GRAY: 59 button = tk.Button(self, text=label, font=('MSゴシック', 20), bg=LIGHT_GRAY, foreground=WHITE) 60 elif color == SMOKE_WHITE: 61 button = tk.Button(self, text=label, font=('MSゴシック', 15), bg=SMOKE_WHITE, foreground=BLACK) 62 elif color == ORANGE: 63 button = tk.Button(self, text=label, font=('MSゴシック', 20), bg=ORANGE, foreground=WHITE) 64 button.grid(column=col, row=row, sticky=(tk.N + tk.S + tk.E + tk.W)) 65 button.bind('<Button-1>', func) 66 self.grid(column=0, row=0, sticky=(tk.N + tk.S + tk.E + tk.W)) 67 68 # create entry 69 self.numbox = tk.Entry(self, background=BLACK, foreground=WHITE, font=('MSゴシック', 30), justify=tk.RIGHT) 70 self.numbox.insert(tk.END, '0') 71 self.numbox.grid(column=0, columnspan=6, row=0, sticky=(tk.N + tk.S + tk.E + tk.W)) 72 73 # frame flex 74 for i in range(0, 7): 75 self.columnconfigure(i, weight=1) 76 self.rowconfigure(i, weight=1) 77 # window flex 78 self.master.columnconfigure(0, weight=1) 79 self.master.rowconfigure(0, weight=1) 80 81 # events 82 def numinput(self, e): 83 pass 84 85 def add(self, e): 86 pass 87 88 def sub(self, e): 89 pass 90 91 def mul(self, e): 92 pass 93 94 def div(self, e): 95 pass 96 97 def equal(self, e): 98 pass 99 100 def clear(self, e): 101 pass 102 103 def point(self, e): 104 pass 105 106 def MC(self, e): 107 pass 108 109 def MR(self, e): 110 pass 111 112 def MS(self, e): 113 pass 114 115 def M_plus(self, e): 116 pass 117 118 def M_sub(self, e): 119 pass 120 121 def in_tax(self, e): 122 pass 123 124 def out_tax(self, e): 125 pass 126 127 def root(self, e): 128 pass 129 130 def plu_sub(self, e): 131 pass 132 133 def CE(self, e): 134 pass 135 136 def percent(self, e): 137 pass 138 139 def fact(self, e): 140 pass 141 142# main 143def main(): 144 root = tk.Tk() 145 root.title('電卓') 146 root.geometry('400x600') 147 calc = Calclator(root) 148 calc.mainloop() 149 150 151if __name__ == '__main__': 152 main() 153
試したこと
謎のパディングがあるのかなと思っているのですが、結局よくわかんないです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/25 14:08