Layout of python code
Question: I'm trying to learn the best way to arrange/define code. Taking the below as
an example, I have to write the tkMessageBox command twice. I did try to
create a def within getText() and refer to that, but it didn't work.

Questions therefore please

1) How could I arrange the code such that I can place the tkMessageBox command
in a def or something and refer to it even within getText()

2) Considering best practice, should this code be layed out differently? If so
how/why?

Thank you in advance

    
    
    import Tkinter as tk
    import tkMessageBox
    import base64
    
    myText = 'empty'
    
    def getText():
        global myText
        myText = inputBox.get()
        entered = "You entered: " + myText
        encoded = "We encoded: " + base64.encodestring(myText)
        Button1 = tk.Button(root, command = tkMessageBox.showinfo("Press me", entered))
        Button1.pack()
        Button2 = tk.Button(root, command = tkMessageBox.showinfo("Press me", encoded))
        Button2.pack()
        root.destroy()
    
    root = tk.Tk()
    
    # Text label
    simpleTitle = tk.Label(root)
    simpleTitle['text'] = 'Please enter your input here'
    simpleTitle.pack()
    
    # The entry box widget
    inputBox = tk.Entry(root)
    inputBox.pack()
    
    # The button widget
    button = tk.Button(root, text='Submit', command=getText)
    button.pack()
    
    tk.mainloop()
    


Answer: I am not sure if you are asking about
[refactoring](http://en.wikipedia.org/wiki/Code_refactoring) your code or not,
but the ultimate style guide for laying out/formatting Python code is [**PEP 8
-- Style Guide for Python Code**](http://www.python.org/dev/peps/pep-0008/).

