내가 오류 "나가서 설명하자면 NameError : 'entryWidget가'정의되지 않은 전역 이름"파이썬 3 오류 : "나가서 설명하자면 NameError : 전역 이름 'entryWidget가'정의되지 않은"
from tkinter import *
import tkinter
def displayText():
tkinter.messagebox.showinfo("Tkinter Entry Widget", "Text value =" + entryWidget)
class Application(Frame):
def createWidgets(self):
root.title("TITLE")
textFrame = Frame(root)
entryLabel = Label(textFrame)
entryLabel["text"] = "Enter the text:"
entryLabel.pack(side=LEFT)
entryWidget = Entry(textFrame)
entryWidget["width"] = 50
entryWidget.pack(side=LEFT)
textFrame.pack()
button = Button(root, text="Submit", command=displayText)
button.pack()
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack()
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
파이썬 3의 Tkinter 다음 코드 조각
코드 자체는 텍스트 상자 옆에 텍스트가있는 텍스트 상자, 텍스트 상자의 입력 단추 및 종료 단추를 만들기 위해 디자인되었습니다. 입력란에 텍스트를 입력하고 Enter 키를 누르면 사용자에게 입력 내용을 알리는 메시지 상자가 나타납니다. 종료 버튼은 스크립트를 종료합니다.
내가 받고있는 오류를 어떻게 해결할 수 있습니까? (이 오류가 의미하는 바는 알고 있으며,이 시나리오에서 해결 방법을 모르겠 음). 필자는 tkinter와 GUI 코드를 처음 접했습니다.
완벽하게 작동합니다. 감사! –