私はいくつかの回答を読んだことがありますが、重複していると思われる質問の多くはかなり個人的なもので、私はここでそれらを適用できるかどうかわかりません)Tkinterオブジェクトには 'tk'という属性はありません
を私に思い出させる私はかなり大きいです。この例外になっている:(そして、クイズのクラスを呼び出す
#main.py
if self.state == self.states["Translate"]:
if self.translate is None:
self.translate = Translate.Translate(self, self.mainFrame)
print("translate frame is none")
print("did not switch")
else:
print("Switched to Quiz")
self.translate.translateFrame.destroy()
self.master.title("Quiz")
self.state = self.states["Quiz"]
self.quiz = Quiz.Quiz(self, self.mainFrame)
すべてを:基本的に
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1550, in __call__
return self.func(*args)
File "/Users/acrobat/PycharmProjects/Jan9coderun/TranslatorVCS/main.py", line 85, in switchMode
self.quiz = Quiz.Quiz(self, self.mainFrame)
File "/Users/acrobat/PycharmProjects/Jan9coderun/TranslatorVCS/Quiz.py", line 84, in __init__
self.makeQuiz()
File "/Users/acrobat/PycharmProjects/Jan9coderun/TranslatorVCS/Quiz.py", line 186, in makeQuiz
self.l = tk.Label(self, textvariable=self.watch.timestr)
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2606, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2132, in __init__
BaseWidget._setup(self, master, cnf)
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2110, in _setup
self.tk = master.tk
AttributeError: 'Quiz' object has no attribute 'tk'
を、別のファイルにそれが通りから始まりo 、再び
class Quiz:
def __init__(self, app, parent):
#self values here...
self.makeQuiz()
私は、コードの上にfrom stopWatch import StopWatch as Watch
としてインポートされたコード
self.watch = Watch(self.playLabel)
self.l = tk.Label(self, textvariable=self.watch.timestr)
self.watch.setTime(self.watch.elapsedtime)
のこのビットを追加するまで、前に働いていたmakeQuiz機能には以下:Fこれは)正常に動作しますストップウォッチは次のようになります:
私はここに別の質問からそのコードを取りましたが、おそらく間違っています。私は別のウィンドウではなく、現在のウィンドウのものを置き換える他のコードのように、これを実装しようとしました。
' self.watch = Watch(self.playLabel) 'では、渡される' parent'引数がルートウィンドウではなく 'Label'オブジェクトであるか、 tk.Frame'インスタンスがあるはずです。 – martineau