私はPythonでスクラブルゲームを作成しようとしています。ユーザーが単語を入力しているときに、その単語が意味する点を表示したいと思います。 どのような方法を使用するのか分かりませんでしたので、私はすでにこの質問をしました。私はどのメソッドを使うべきかを発見したので、このメソッドを使う方法について質問しましたが、これは新しい質問に値すると思います。 私の問題は、bind_entry(event)
という関数を作成したことで、ユーザーが文字を入力するたびにラベルを設定するはずです。しかし、関数bind_entry(event)
は、設定するラベルとその単語が入っている項目を知らない。ここでPython 2.7:Tkinter、バインドメソッドの使い方は?
が私のコードです:
#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
として
は私が機能bind_entry()
でval_entry_word
とval_points
を呼び出すことができますどのように他のファイル内の関数で作成されますので、ここで
は私の質問ですか?
私は 'bind_entry'に' m'が何であるのかよく分かりません。また、 'counting_point'にはどのような入力がありますか?論理推測は文字列ですが、あなたが何をしているのかは不明です。 'char'とは何ですか?私が言うことができる限り、それはPythonの組み込みではありません... – mgilson