그래서 몇 가지 답변을 읽었을 것입니다.하지만 대부분 중복되는 질문은 꽤 개인적이며 여기에 적용 할 수 있는지 여부는 모르겠습니다.)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'
을 다른 파일에 같이 시작합니다 영형 는 다시
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이) 잘 작동 스톱워치는 다음과 같이 보입니다.
나는 여기에 다른 질문의 코드를 가지고 갔지만 아마 잘못 작성했을 것입니다. 별도의 창은 아니지만이 기능을 다른 Windows의 코드처럼 구현하여 현재 창에있는 내용을 대체하려고했습니다.
'self.watch = Watch (self.playLabel)'에서 전달되는'parent' 인자가 루트 윈도우가 아닌'Label' 객체이거나' tk.Frame' 인스턴스가 있어야합니다. – martineau