Я начинаю с Python 3, и у меня возникают проблемы с получением значения из виджета tkinter. Когда я запускаю свой код, я получаю ошибку «имя edtGetMe не определено». Может кто-нибудь увидеть, где я иду не так?
from tkinter import *
# Define the class that forms my window.
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
# Init the class.
def init_window(self):
# Place widgets on the window.
self.pack(fill=BOTH, expand=1)
# Quit button.
btnCancel = Button (self, text="Cancel", command=self.cancel_out)
btnCancel.place (x=10, y=120)
# Action button.
btnAction = Button (self, text="Set Text", command=self.action)
btnAction.place (x=100, y=120)
# The Editboxes.
edtGetMe = Entry (self)
edtSetMe = Entry (self)
edtGetMe.place (y=10, x=10, width=380, height=100)
edtSetMe.place (y=155, x=10, width=380, height=100)
def cancel_out(self):
exit()
def action (self):
# Get the entry from the GetMe box.
self.usrText = edtGetMe.get()
# Stuff it into the other box.
edtSetMe.insert(self.usrText)
def main():
root = Tk()
# Size of window.
root.geometry("400x300")
# Start Window Class.
app = Window(root)
root.mainloop()
если name == " main ": main ()