0

I am a newbie struggling to get two simple string inputs out of a text widget and use it later in my program. How do I migrate the strings keypad and message to input them elsewhere?

#Text widget to input 2 text strings and store as 'keypad' and 'message'
from tkinter import *
master = Tk()
master.title("simple one time pad")
master.resizable(0,0)

global keypad
global message

k = Text(master, width=50,height=10)
k.pack()

separator = Frame(height=2, bd=1, relief=SUNKEN)
separator.pack(fill=X, padx=5, pady=5)

m = Text(master, width=50,height=10)
m.pack()

def encrypt():         
    keypad = (k.get(1.0, END))
    str(keypad)
    message = (m.get(1.0, END))
    str(message)

    print(keypad)
    print(message)            

mb = Button(master, text="Encrypt", command=encrypt)
mb.pack(anchor=N)

mainloop()

print(keypad)
print(message)

Gives the following error:

Traceback (most recent call last):
  File "/home/maverick/Window-hell-1.py", line 39, in <module>
    print(keypad)
NameError: name 'keypad' is not defined

I get the first set of print() In the def encrypt: but crashes after the mainloop(). I tried the whole self.xxx routine but then my widget wouldn't function.

martineau
  • 119,623
  • 25
  • 170
  • 301

0 Answers0