回答編集履歴
1
追記
test
CHANGED
@@ -89,3 +89,67 @@
|
|
89
89
|
root.mainloop()
|
90
90
|
|
91
91
|
```
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
teamiklさん提案のfunctools.partialを使った例
|
96
|
+
|
97
|
+
-----
|
98
|
+
|
99
|
+
```Python
|
100
|
+
|
101
|
+
from tkinter import *
|
102
|
+
|
103
|
+
from tkinter import ttk
|
104
|
+
|
105
|
+
import functools
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
root = Tk()
|
110
|
+
|
111
|
+
root.title('Checkbutton')
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
frame1 = ttk.Frame(root, padding=(10))
|
116
|
+
|
117
|
+
frame1.grid()
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
def after_cb(row, col, var):
|
122
|
+
|
123
|
+
print( f'{row+1},{col+1}={var.get()}')
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# 1つのcheckbuttonを初期化
|
128
|
+
|
129
|
+
def init_check( frm, row, col):
|
130
|
+
|
131
|
+
var = BooleanVar()
|
132
|
+
|
133
|
+
var.set(False)
|
134
|
+
|
135
|
+
f = functools.partial(after_cb, row, col, var)
|
136
|
+
|
137
|
+
#print(id(f))
|
138
|
+
|
139
|
+
cb = ttk.Checkbutton( frm, padding=10, text=f'{row+1}x{col+1}', variable=var, command=f)
|
140
|
+
|
141
|
+
cb.grid(row=row, column=col)
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
for row in range(2): # 行
|
146
|
+
|
147
|
+
for col in range(3): # 列
|
148
|
+
|
149
|
+
init_check( frame1, row, col)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
root.mainloop()
|
154
|
+
|
155
|
+
```
|