Question: There is a huge matrix whose elements are numbers in the range of 1 to 15. I want to transform the matrix to the one whose elements be letters such that 1 becomes "a", 2 becomes "b", and so on. As a simple example:

```
import pandas as pd
import numpy as np, numpy.random
numpy.random.seed(1)
A = pd.DataFrame (np.random.randint(1,16,10).reshape(2,5)) 
# A     0   1   2   3   4
#   0   6   12  13  9   10
#   1   12  6   1   1   2

```

The expected output is

```
# B     0   1   2   3   4
#   0   f   l   m   i   j
#   1   l   f   a   a   b

```

I can do it with a loop but for a huge matrix, it doesn't seem logical. There should be a more pythonic way to do it. In `R`, `chartr` is the function for such a replacement. For the numbers between 1 to 9, it works like this: `chartr("123456789", "ABCDEFGHI", A)`. What is the equivalent in Python?

Answer: 
You use a class because the class instance and it's variables remain after tkinter exits.<https://www.tutorialspoint.com/python/python_classes_objects.htm> And you may want to reexamine some of your documentation requirements, i.e. when the statement is
"root.title('Title of the window')", adding the explanation "#title of the window" is just a waste of your time..

```
""" A simplified example
"""

import sys
if 3 == sys.version_info[0]:  ## 3.X is default if dual system
    import tkinter as tk     ## Python 3.x
else:
    import Tkinter as tk     ## Python 2.x

class GetEntry():
    def __init__(self, master):
        self.master=master
        self.entry_contents=None
        self.e = tk.Entry(master)
        self.e.grid(row=0, column=0)
        self.e.focus_set()

        tk.Button(master, text="get", width=10, bg="yellow",
               command=self.callback).grid(row=10, column=0)

    def callback(self):
        """ get the contents of the Entry and exit
        """
        self.entry_contents=self.e.get()
        self.master.quit()

master = tk.Tk()
GE=GetEntry(master)
master.mainloop()

print("\n***** after tkinter exits, entered =", GE.entry_contents)

```
1. In python, functions are *objects*, as in `get_values` is an object.
2. Objects can have attributes.

Using these two, and the knowledge that we can't really return from a button command, we can instead attach an attribute to an already global object and simply use that as the return value.

Example with button
===================

```
try:                        # In order to be able to import tkinter for
    import tkinter as tk    # either in python 2 or in python 3
except ImportError:
    import Tkinter as tk

def on_button_press(entry):
    on_button_press.value = entry.get()
    entry.quit()

def main():
    root = tk.Tk()
    entry = tk.Entry(root)
    tk.Button(root, text="Get Value!", command=lambda e = entry : on_button_press(e)).pack()
    entry.pack()
    tk.mainloop()
    return on_button_press.value

if __name__ == '__main__':
    val = main()
    print(val)

```

---

Minimalistic example
====================

3. Similarly modules are also objects, if you want to avoid occupying global namespace extremely, you can attach a new attribute to the module you're using

See:

```
try:                        # In order to be able to import tkinter for
    import tkinter as tk    # either in python 2 or in python 3
except ImportError:
    import Tkinter as tk

if __name__ == '__main__':
    tk.my_value = lambda: [setattr(tk, 'my_value', entry.get()), root.destroy()]
    root = tk.Tk()
    entry = tk.Entry(root)
    root.protocol('WM_DELETE_WINDOW', tk.my_value)
    entry.pack()
    tk.mainloop()
    print(tk.my_value)

```