前提・実現したいこと
tkinterを使用しています.
ボタンを複数作るにあたり,ループで記述しました(ソースコード参照).
しかし,ボタンごとに呼び出す関数を変える方法が分からず困っております.
良い記述方法はないでしょうか.
よろしくお願いいたします.
該当のソースコード
python3
1import tkinter as tk 2import numpy as np 3from matplotlib import pyplot as plt 4from PIL import Image as img 5 6bTxtList = ["Plot", "Paint"] 7eInitList = [0, 0, 0] 8 9class Application(tk.Frame): 10 def __init__(self, master = None): 11 tk.Frame.__init__(self, master) 12 self.pack(expand = 1, fill = tk.BOTH, anchor = tk.NW) 13 self.createWidgets(bTxtList, eInitList) 14 15 def createWidgets(self, bTxtList, eInitList): 16 for eInit in eInitList: 17 e = tk.Entry() 18 e.insert(tk.END, eInit) 19 e.pack(expand = 1, fill = tk.BOTH, anchor = tk.NW) 20 21 for bTxt in bTxtList: 22 b = tk.Button(text = bTxt) 23 b.bind("<Button-1>", lambda evt: ??????) 24 b.pack(expand = 1, fill = tk.BOTH, anchor = tk.NW) 25 26 canvas = tk.Canvas(self, bg = 'white') 27 canvas.pack() 28 29 30root = tk.Tk().title("Visualizer for function") 31app = Application(master = root) 32app.mainloop()
試したこと
ソースコードのbTxtListをDictにして,keyをボタンのテキストにし,valueを呼び出す関数にして?????に入れればできるかなと考えたのですが,よくわからず挫折しました.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/14 15:55