2017-01-17 16 views
-1

私のクラスの中のtkinterウィジェットにこのエラーがあります。私が理解していないことは、実際にエラーが私に伝えようとしていることと、どこが間違っているのかです。ここでPython - tkinterウィジェットがうまく動作しない、さらに私が得たトレースバックを理解できない

File "/usr/lib/python3.5/tkinter/ttk.py", line 553, in __init__ 
    tkinter.Widget.__init__(self, master, widgetname, kw=kw) 
File "/usr/lib/python3.5/tkinter/__init__.py", line 2142, in __init__ 
    (widgetName, self._w) + extra + self._options(cnf)) 
    _tkinter.TclError: unknown option "-command" 

コードされています: - それは、ラインが表示されているはずです

def play(): 
     while True: 
      if self.questions_asked == 20: 
       answer_label = ttk.Label(self , text="That's the end of the quiz. Your score for that round was {}! ") 
       answer_label.pack() 
       break 
      self.random_question = random.randint(0,39) 

      while not self.random_question in self.questions: 
       self.random_question = random.randint(0,39) 

      question_label = ttk.Label(self, text="Question {} : {}".format(i , self.questions[self.random_question])) 
      question_label.pack() 

      check_answer = ttk.Button(self, text="Check your answer.", command=lambda:check()) 
      check_answer.pack() 

      remove_key(self.random_question, self.questions) 
      remove_key(self.random_question, self.answers) 
      self.questions_asked +=1 

     def check(): 

      get_user_entry = entry_box.get() 
      if get_user_entry == None: 
       question_label = tkinter.Label(self, text="Please put an answer into the entry box.") 
       question_label.pack() 

      if get_user_entry == "end": 
       question_label = tkinter.Label(self, text="Thanks for playing! ") 
       question_label.pack() 
       lambda: shown_frame.show_frame(OpeningFrame) 

      else: 
       verify_answer(get_user_entry, self.random_question, self.questions) 
       if verify_answer == True: 
        answer_label = ttk.Label(self, text="You got it correct !") 
        answer_label.pack() 
       else: 
        answer_label = ttk.Label(self, text="Sorry the answer was {}".format(self.answers[self.random_question])) 
        answer_label.pack() 


    overhead_label = ttk.Label(self, text="Welcome to the Quiz page. Click the button below to start.") 
    overhead_label.pack() 

    entry_box = tkinter.Entry(self) 
    entry_box.pack() 

    start_quiz = ttk.Button(self, text="Start the quiz.", command=play()) 
    start_quiz.pack() 


    home_button = ttk.Button(self, text="Go back to home page", command=lambda: shown_frame.show_frame(OpeningFrame)) 
    home_button.pack(pady=15, padx=15) 
+0

あなたの 'start_quiz'ボタンにコマンドを割り当てるとき、あなたがそれを割り当てるときに' play() ')を呼び出すのではなく、**呼び出し可能な**' play'を割り当てます。例: '...、command = play)' – Jkdc

+0

あなたのコードをそのまま実行することはできませんので、エラーは表示されません。インポートやプレイ機能を含むクラスはありません。エラーをトリガする最小の実行可能コードをポストする必要があります。 –

+0

は常にFULLエラーメッセージ(トレースバック)を表示します。あなたはメッセージの一部だけを表示し、コード内のどの行が問題になるかわかりません。ウィジェットの中には 'command ='はありませんが、このタイプのウィジェットでは 'command ='を使っています。これがあなたのエラーメッセージです。 – furas

答えて

0

あなたはフルエラーメッセージ(トレースバック)が表示されませんでしたが、私は、コードを実行するたびにここで私が受け取るエラーです問題を引き起こすあなたのコード。

このオプションを持たないウィジェットでcommand=を使用していると思います。これがエラーメッセージです。

+0

これは完全なトレースバックではありませんでした。私はそれをもう一度チェックし、それに行番号は含まれていませんでした。 –

+0

ええ、それは、私はラベルのウィジェットでコマンドを使用して...ありがとう –

関連する問題