this is probably a stupid question, but I've been using Python for a little while now and wanted to try some GUI programming with tkinter. I'm just trying to achieve a simple thing, get a guy with an entry field in which I type whatever, press a button which will then show the text in a label. Here is my try at doing this:
from tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() entry1 = Entry(frame) entry1.grid(row=0) self.button = Button(frame, text="Get text", command=get_text).grid(row=2) def get_text(): text = entry1.get() text = text.set(text) lbl1 = Label(frame, textvariable=text).grid(row=1) root = Tk() app = App(root) root.mainloop()
this, however, gives me the error "NameError: global name 'entry1' is not defined" when I hit the button. I have tried to change the indentation of def get_text(): one step to the right, but then I get "NameError: global name 'get_text' is not defined".
I thought this was a good example to start understanding some tkinter but it turns out to be a nightmare. I have gone through a few examples on the net but I don't seem to find one that shows what I'm trying to do.
Any help in the right direction or some good tkinter tutorial would be awesome.