title: Declaring a variable global not working throughout code snippet
body: <p>Below is a code snippet which gives the user 4 options. To either: encrypt a message, decrypt a message, change the <code>encryption_code</code> or to show the <code>encryption_code</code>. </p>
  
  <pre><code>import tkinter
  from tkinter import *
  from tkinter import ttk
  from tkinter.ttk import *
  
  letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  
  encryption_code = 'LFWOAYUISVKMNXPBDCRJTQEGHZ'
  letters += letters.lower()
  encryption_code += encryption_code.lower()
  enc = dict(zip(letters,encryption_code))
  
  dec = dict(zip(encryption_code, letters))
  
  window = tkinter.Tk()    
  
  style = ttk.Style(window)
  style.configure("BW.TLabel")
  
  encrypt_frame = tkinter.Frame(window)
  
  encrypted_frame = tkinter.Frame(window)
  
  change_frame = tkinter.Frame(window)
  changed_frame = tkinter.Frame(window)
  
  entry = tkinter.Entry(encrypt_frame)
  encrypt_entry = tkinter.Entry(change_frame)
  
  encryptget = encrypt_entry.get()
  
  def code_change():
      global changed_frame
      global encrypt_entry
      global encryption_code
      global encryptget
  
      if len(encryptget) == 26:
          encryption_code = encryptget
          encryption_code += encryption_code.lower()
          changed_label.configure(background=window.cget('bg'))
          changed_label.config(text="You have successfully changed the encryption code!")
          change_header.config(text="Your code is: " + str(encryptget.upper()))
          changed_frame.pack_forget()
          changed_label.pack()
          changed_frame.pack()
  
  
  def encrypt():
      global encrypt_frame
      entry.focus_set()
      entry.pack()
      encrypt_confirm.pack()
      back_button.pack()
      encrypt_frame.pack()
      first_frame.pack_forget()
  
  def display_encrypt():
      global encryption_code
      if len(entry.get()) &gt; 0:
          display_enc = "".join([enc.get(ch, ch) for ch in entry.get()])
          entry.delete(0, tkinter.END)
          new_message.config(background=window.cget('bg'))
          new_message.config(text=str(display_enc))
          new_message.pack()
          encrypted_frame.pack()
  
  def back():
      new_message.pack_forget()
      entry.delete(0, tkinter.END)    
      first_frame.pack()
      encrypt_frame.pack_forget()
      encrypted_frame.pack_forget()
      change_frame.pack_forget()
      changed_frame.pack_forget()
  
  def change_code():
      global change_frame
      encrypt_entry.focus_set()
      encrypt_entry.pack()
      change_confirm.pack()
      back_button4.pack()
      change_frame.pack()
      first_frame.pack_forget()
  
  first_frame = tkinter.Frame(window)
  encrypt_button = ttk.Button(first_frame, text="Encrypt", width=20, command=encrypt)
  change_code = ttk.Button(first_frame, text="Change code", width=20, command=change_code)
  encrypt_button.pack()
  change_code.pack()
  first_frame.pack()
  
  back_button = ttk.Button(encrypt_frame, text="Back", width=20,  command=back)
  back_button4 = ttk.Button(change_frame, text="Back", width=20,  command=back)
  
  encrypt_confirm = ttk.Button(encrypt_frame, text="Confirm", width=20,  command=display_encrypt)
  
  new_message = tkinter.Label(encrypted_frame, text="", font=('Helvetica', 10))
  
  change_confirm = ttk.Button(change_frame, text="Confirm", width=20,  command=code_change)
  
  window.mainloop()
  </code></pre>
  
  <p>My problem is that declaring <code>encryption_code</code> global is not working throughout my code. The functions where it doesn't work is <code>def display_encrypt</code> and <code>def display decrypt</code> (the <code>encryption_code</code> stays as LFWOAYUISVKMNXPBDCRJTQEGHZ even if the user has changed it) whereas in other functions, it works perfectly.</p>
  
  <p>For example, you change the encryption code to QWERTYUIOPASDFGHJKLZXCVBNM and then go to encrypt and type ABC. It should be encrypted to QWE but instead is encrypted to LFW(the original encryption code)</p>