Pythonの質問です。
Q&A
tkinterで大量のラベルを作る際に以下のことを試しました。
def label_maker(label_name,column,row)
exec(label_name) = tk.Label(root)
exec(label_name).grid(column=column,row=row)
for i in range(4)
for j in range(29)
temp = 'ml' + str(i) + str(j)
label_maker(temp,i,j)
execで文字列を変数として扱えるというのをみたので試してみましたが、
SyntaxError:cannot assign to function call here. Maybe you meant '==' instead of '='?
と出ました。
exec(label_name) = を==に変えて実行したところ
name 'ml00' is not definedが出ました。
試しに関数内のexecの前に
ml00 = tk.Label(root)
を書き加えて実行したところ
'NoneType' object has no attribute 'grid'
となり、お手上げ状態です。
ラベルを一気に作る方法はありますでしょうか?