This is just a simple practice of Python Tkinter. Here is the code:
from tkinter import *
class Window(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.master.title('GUI')
self.pack(fill=BOTH, expand=1)
text = Entry(self, bd=1)
text.pack(side = TOP)
submit_b = Button(self, text = 'submit', command = self.submit)
submit_b.pack(side = BOTTOM)
def submit(self):
print(self.text.get())
root = Tk()
root.geometry('200x50')
app = Window(root)
root.mainloop()
The result is like this:
So I enter a string in the 'Entry' and click 'submit' button. This program will print out the string.
However, I got this:
AttributeError: 'Window' object has no attribute 'text'
I have no idea why it didn't work. Please help me!