Python でスクラブル ゲームを作成しようとしています。ユーザーが単語を入力しているときに、その単語が値するポイントを表示したいと思います。どの方法を使用すればよいかわからなかったので、すでにこの質問をしました。どの方法を使用するかを発見したので、私の質問はこの方法の使用方法に関するものであるため、これは新しい質問に値すると思います。私の問題はbind_entry(event)
、ユーザーが文字を入力するたびにラベルを設定するという関数を作成したことです。しかし、関数bind_entry(event)
は、設定するラベルと、単語が存在するエントリを認識していません。
これが私のコードです:
#this the function creating the label
def create_variabletext_intlabel(root,col,row):
val=IntVar()
label=Label(root,textvariable=val)
label.grid(column=col,row=row)
return val, label
#this is the function creating the entry
def create_entry_string(root,width,col,row,columnspan,rowspan):
val=StringVar()
entry=ttk.Entry(root,width=width,textvariable=val)
entry.grid(column=col,row=row,columnspan=columnspan,rowspan=rowspan)
entry.bind("<Any-KeyPress>",bind_entry)
#Here is my problem, when I call the function bind_entry.
return val, entry
def bind_entry(event):
label.set(m.counting_point(char(event)))
# m.counting_point() is a function counting the word's points
# my problem is that the function doesn't know yet the label.
# I don't know how to call the label.
# I call the function create_entry_string in another file initiating
# all the widget for the GUI
val_entry_word, entry_word =g.create_entry_string(root,15,1,1,1,1)
# I call the function create_variabletext_intlabel in another file
# initiating all the widget for the GUI
val_points,label_points=g.create_variabletext_intlabel(root,1,2)
m.counting_points()
この関数は、ユーザーが入力した文字のみをカウントすることに気付きました。ここで に電話する必要がありますval_entry_word
。
だからここに私の質問があります:
val_entry_word
とは別のファイルの関数で作成されているので、関数でとval_points
を呼び出すにはどうすればよいですか?val_entry_word
val_points
bind_entry()