2017-02-10 8 views
1

私はこのことについてお詫びします。私は今日、pythonを学び始めました。私はそれを周りに探しました。は私の問題のようにがかなり簡単に解決できるように見えますが、私は問題を抱えています。私の現在のコード:Pythonのキーバインディング:TypeError:引数を受け取りません(1件あり)

master = Tk() 

master.wm_title("V3") 
w = Label(master, text="Code:") 
w.pack() 
master.resizable(width=False, height=False) 
e = Entry(master, width = 35, justify = CENTER) 
master.geometry('{}x{}'.format(240, 235)) 
e.pack() 
e.focus_set() 

def decode(): 
     textField.configure(state="normal") 
     textField.delete(1.0,END) 
     hint = e.get() 
     for i, c in enumerate(hint): 
       if i<5: 
        textField.insert(END,cypher1[c]) 
       if i>=5: 
        textField.insert(END,cypher2[c]) 
     master.clipboard_clear() 
     master.clipboard_append(textField.get("1.0",'end-1c')) 
     textField.configure(state="disabled") 
     copyLabel.config(text = "Code Copied!") 


b = Button(master, text = "Generate and Copy Key", width = 25, height = 2, command = decode) 
b.pack() 

textField = Text(master, height=3, width=35) 
textField.pack() 
copyLabel = Label(master, text="") 
copyLabel.pack() 
master.bind('<Return>', decode) 


mainloop() 

それは素晴らしい作品です! ...私はenterを押すことを除いて。そして、それは私が

master.bind('<Return>', decode()) 

にそれを変更しようとした TypeError: decode() takes no arguments (1 given) になり、それがエラーをスローしませんが、それだけで何もしません。私はオブジェクトの不足がおそらく問題を引き起こしていると思う。

お手数ですが、ありがとうございます。

+0

の任意の数を食べるであろう。 'master.bind( ''、decode())の問題は' decode'によって返された*値をバインドすることです。これは 'None'です。 –

+0

'bind'コマンドを書いているほとんどの参考文献は、バインドされた関数に渡される引数について説明しています。 –

答えて

0

.bind()関数にeventを渡し:

def decode(event=None):又はdef decode(*_):多分引数を取るよう `decode`を定義引数

+0

@AONあなたの場合、あなたは自分自身を得ていると思います(デコードの中で 'type(event)'を表示することでテストできますが、どちらの方法でも使用していないので、 'def decode ): ' – TemporalWolf

+0

@ TemporalWolf3実際には、' def decode(event) 'と' def decode(_) 'の両方がキーバインドのために働いていましたが、この場合はボタンクリックを破ったので、同じ場合' TypeError:decode )はちょうど1つの引数(与えられた0) 'をとります。 – AON

+0

@AONデフォルト値を追加してください:私の回答を更新しました – TemporalWolf

関連する問題