ZykBee
Newbie
- Oct 30, 2017
- 4
- 0
I can't get it to print 'congrats' when I type "password" in the window. I'm pretty sure the issue is in the "content =self.text.get()" line, but I I haven't an idea what it should be. Any ideas?
<<<
from tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text = "Enter PW")
self.instruction.grid(row = 0, column=0, columnspan = 3, sticky = W)
self.text = Text(self, width = 35, height =5, wrap = WORD)
self.text.grid(row =1, column=1, sticky = W)
self.submit_button = Button(self, text = "Submit", command = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky =W)
self.text1 = Text(self, width = 35, height =5, wrap = WORD)
self.text1.grid(row = 3, column =0, columnspan = 2, sticky=W)
def reveal (self):
content = self.text.get(1.1, END)
if content == "password":
message = "congrats"
else:
message = "denied"
self.text1.insert(3.0, message)
root = Tk()
root.title("password")
root.geometry("250x250")
app = Application(root)
root.mainloop()
>>>
<<<
from tkinter import *
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text = "Enter PW")
self.instruction.grid(row = 0, column=0, columnspan = 3, sticky = W)
self.text = Text(self, width = 35, height =5, wrap = WORD)
self.text.grid(row =1, column=1, sticky = W)
self.submit_button = Button(self, text = "Submit", command = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky =W)
self.text1 = Text(self, width = 35, height =5, wrap = WORD)
self.text1.grid(row = 3, column =0, columnspan = 2, sticky=W)
def reveal (self):
content = self.text.get(1.1, END)
if content == "password":
message = "congrats"
else:
message = "denied"
self.text1.insert(3.0, message)
root = Tk()
root.title("password")
root.geometry("250x250")
app = Application(root)
root.mainloop()
>>>