2016-10-06 2 views
0

다음은 간단한 GUI GUI 프로그램입니다. 그러나 bat 파일에서 열려고하면 오류가 발생합니다.파이썬 코드는 작동하지만 bat 파일을 통해 열기 오류가 발생합니다

박쥐 파일 (2 선) :

ch10.2.py 
pause 

I 나타나는 오류는 다음과 같습니다

[텍스트 형식으로 오류 메시지가 여기에 포함되는]

내 코드 :

# Lazy Buttons 2 
# Demonstrates using a class with Tkinter 

from tkinter import * 

class Application(Frame): 
    """ A GUI application with three buttons. """ 
    def __init__(self, master): 
     """ Initialize the Frame. """ 
     super(Application, self).__init__(master)  
     self.grid() 
     self.create_widgets() 

    def create_widgets(self): 
     """ Create three buttons that do nothing. """ 
     # create first button 
     self.bttn1 = Button(self, text = "I do nothing!") 
     self.bttn1.grid() 

     # create second button 
     self.bttn2 = Button(self) 
     self.bttn2.grid() 
     self.bttn2.configure(text = "Me too!") 

     # create third button 
     self.bttn3 = Button(self) 
     self.bttn3.grid() 
     self.bttn3["text"] = "Same here!" 

# main 
root = Tk() 
root.title("Lazy Buttons 2") 
root.geometry("200x85") 
app = Application(root) 
root.mainloop() 
+5

오류가 무엇입니까 아래 참조 ? 그리고 오류없이 실행하기 위해 사용하는 정확한 명령은 무엇이며, 2.x와 3.x가 모두 설치되어 있습니까? –

+2

게시물에 스크린 샷의 스크린 샷을 포함하지 마세요. 여기에 실제 오류를 붙여 넣으십시오. –

+2

어쩌면 주 interprenter 파이썬 3.5 아니야? 2.7 또는 더 오래된 것? – Broly

답변

0

super(Application, self).__init__(master)에 오류가 있습니다.
Frame.__init__(self, master)으로 바꾸면 작동합니다.

# Lazy Buttons 2 
# Demonstrates using a class with Tkinter 

from tkinter import * 

class Application(Frame): 
    """ A GUI application with three buttons. """ 

    def __init__(self, master): 
     """ Initialize the Frame. """  
     Frame.__init__(self, master) 
     #super(Application, self).__init__(master) 
     self.grid() 
     self.createWidgets() 




    def createWidgets(self): 
     """ Create three buttons that do nothing. """ 
     # create first button 
     self.bttn1 = Button(self, text = "I do nothing!") 
     self.bttn1.grid() 

     # create second button 
     self.bttn2 = Button(self) 
     self.bttn2.grid() 
     self.bttn2.configure(text = "Me too!") 

     # create third button 
     self.bttn3 = Button(self) 
     self.bttn3.grid() 
     self.bttn3["text"] = "Same here!" 


# main 
root = Tk() 
root.title("Lazy Buttons 2") 
root.geometry("200x85") 
app = Application(root) 
root.mainloop() 

OUTPUT
enter image description here

+0

고맙습니다. 문제는 2.7 버전과 3.5 버전입니다.) – Grigorie

관련 문제