複数のウィジェットを1つの「バインド」でバインドする方法が不思議です。 expampleについてはTkinterで複数のウィジェットをバインドする方法を教えてください。
:
私は、次の3つのボタンを持っていると私はホバリングの後に自分の色を変更したいです。
from Tkinter import *
def SetColor(event):
event.widget.config(bg="red")
return
def ReturnColor(event):
event.widget.config(bg="white")
return
root = Tk()
B1 = Button(root,text="Button 1", bg="white")
B1.pack()
B2 = Button(root, text="Button2", bg="white")
B2.pack()
B3 = Button(root, text= "Button 3", bg="white")
B3.pack()
B1.bind("<Enter>",SetColor)
B2.bind("<Enter>",SetColor)
B3.bind("<Enter>",SetColor)
B1.bind("<Leave>",ReturnColor)
B2.bind("<Leave>",ReturnColor)
B3.bind("<Leave>",ReturnColor)
root.mainloop()
私の目標は、上記の6つではなく、2つのバインド(「Enter」と「Leave」イベント)を持つことです。
は、複数のオブジェクトに同じことをやって任意のアイデア
また、ネストされた辞書を使用してパラメータを設定することもできます: 'bParams = {'button1':{'bg': 'red'、 'command' = self.frame.quit、...}、... } '。あなたが辞書にコマンドを追加できるかどうかは分かりませんが、それ以外の場合、 'b = Button(root、text = s、bg = bParams [b]、...)'とすることができます。 –
ああ、ありがとう。それは働くかもしれない:) –