0
첫 번째 tkinter 앱을 실행하려고하는데 다음과 같이 오류가 발생합니다. '프레임'이 같은 클래스의 함수에 표시되지 않는 이유는 무엇입니까? 아래다음 Tkinter 프로그램에 어떤 문제가 있습니까?
Traceback (most recent call last):
File "C:\Data\Personal\Python\Tkinter\GUI_ver1.py", line 25, in <module>
myapp = App(root)
File "C:\Data\Personal\Python\Tkinter\GUI_ver1.py", line 7, in __init__
self.createWidgets()
File "C:\Data\Personal\Python\Tkinter\GUI_ver1.py", line 10, in createWidgets
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
NameError: global name 'frame' is not defined
내 프로그램 :
from Tkinter import *
class App(Frame):
def __init__(self, master=None):
frame = Frame(master)
frame.pack()
self.createWidgets()
def createWidgets(self):
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
self.hi_there.pack({"side": "right"})
def say_hi(self):
print "hi there, everyone!"
root = Tk()
# create the application
myapp = App(root)
myapp.master.title("My First App")
myapp.master.geometry('450x130')
myapp.master.resizable(0,0)
# start the program
root.mainloop()