title: Multiple commands to a button in tkinter
body: <p>I'm a car park admittance thingy for college. Basically what is does when it's run, a window comes up, asks the user to enter make, model, colour, and reg plate. Then it saves this data to a list, array or whatever. The user presses a button to enter their car into the car park, and also to see what cars are currently in the car park. When I press admit vehicle, I need the data to be saved to this list/array/tree, and also for a integer variable to decrease by one. Here's the relevant code. There is more, but this is the relevant bits.</p>
  
  <pre><code># Admit Button
      btn_admit = ttk.Button(bottom_frame)
      btn_admit.config(text='Admit Vehicle')
      btn_admit.bind('&lt;Button-1&gt;', self.admit)  # I need this to reduce the variable as well
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    def admit(self, event):
          self.useful_msg.set("Vehicle Admitted")  # This is only here to show a message currently it does nothing else
  </code></pre>
  
  <p>This is the 'spaces available' variable:</p>
  
  <pre><code>self.num_spaces = IntVar(mid_frame)
      self.num_spaces.set = 0
      lbl_num_spaces = Label(mid_frame)
      lbl_num_spaces.config(textvariable=self.num_spaces, bg='yellow')
  </code></pre>
  
  <p>Finally, this is the code for the window that shows the tree of cars that are in the car park (with some example cars hard-coded for now):</p>
  
  <pre><code>class ShowCarsGui:
  def __init__(self, master):
      self.master = master
      self.master.geometry('1200x600+100+100')
  
      # Frames
      top_frame = tk.Frame(self.master)
      tree_container = tk.Frame(self.master)
      bottom_bar = tk.Frame(self.master)
  
      # Widgets:
  
      # Logo
      carpark_icon = tk.PhotoImage(file='car.gif')
      lbl_carpark_icon = tk.Label(top_frame)
      lbl_carpark_icon.config(image=carpark_icon)
      lbl_carpark_icon.image = carpark_icon
  
      # Header
      lbl_header = tk.Label(top_frame)
      lbl_header.config(text="Vehicles in car park", font='helvetica 32 bold')
  
      # Tree(ttk)
      self.tree = ttk.Treeview(tree_container)
      self.tree["columns"] = ("Make", "Model", "Colour", "Registration")
      self.tree["height"] = 10
      self.tree["show"] = 'headings'  # Gets rid of default first column
      vsb = ttk.Scrollbar(tree_container)
      vsb.configure(orient='vertical', command=self.tree.yview)
      hsb = ttk.Scrollbar(tree_container)
      hsb.configure(orient='horizontal', command=self.tree.xview)
      self.tree.configure(yscroll=vsb.set, xscroll=hsb.set)
      self.tree_populate()
  
      # Button
      quit_button = tk.Button(bottom_bar)
      quit_button.config(text='Quit', width=25)
      quit_button.bind('&lt;Button-1&gt;', self.close_window)
  
      # Positioning frames
      top_frame.grid_rowconfigure(0, minsize=150)  # Make row 150 pixels high
      top_frame.grid(row=0)
      tree_container.grid(row=1)
      bottom_bar.grid(row=2)
  
      # Top
      lbl_carpark_icon.grid(row=0, column=0, padx=10, sticky='w')
      lbl_header.grid(row=0, column=1, padx=20)
  
      # Middle
      self.tree.grid(column=0, row=0, sticky='nsew')
      vsb.grid(column=1, row=0, sticky='ns')
      hsb.grid(column=0, row=1, sticky='ew')
  
      # Bottom
      quit_button.grid(row=0, column=0)
  
  def close_window(self, event):
      self.master.destroy()
  
  def tree_populate(self):
      # Eventually this needs to come from car park object
      tree_columns = ("Make", "Model", "Colour", "Registration")
      tree_data = [
          ("Ford", "Ka", "Blue", "FD54 2WE"),
          ("Vauxhall", "Corsa", "Green", "KJ61 9YH"),
          ("VW", "Polo", "Silver", "AA54 9TQ"),
          ("Nissan", "Qashqai", "Red", "YRE 456W"),
          ("Toyota", "Starlet", "Gold", "J234 WYE"),
      ]
  
      for col in tree_columns:
          self.tree.heading(col, text=col, anchor='w')
      for country_data in tree_data:
          self.tree.insert("", 0, values=country_data)
  </code></pre>
  
  <p>Finally here is the code for the entire program:</p>
  
  <pre><code>import tkinter as tk
  from tkinter import *
  from tkinter import ttk
  
  
  class CarParkGui:
      def __init__(self, master):
          self.master = master
          self.master.configure(bg='light cyan')
          self.master.title("Collyer's Car Park")
          self.master.option_add('*Font', 'Georgia 12')  # Font for all             widgets
          self.master.option_add('*Font', 'helvetica 20 bold')
          self.master.option_add('*Background', 'light cyan')  # background of all widgets
          self.master.geometry('1200x500+100+100')  # w,h,x,y (top left corner)
          self.top()  # Build top bar
          self.middle()  # Define middle frame
          self.bottom()  # Define Bottom Frame
  
      def top(self):
          # Frame for top section
          top_frame = Frame(self.master)
  
          # Logo
          carpark_icon = PhotoImage(file='car.gif')
          lbl_carpark_icon = Label(top_frame)  # Instance of tkinter label (parent is frame)
          lbl_carpark_icon.config(image=carpark_icon)
          lbl_carpark_icon.image = carpark_icon  # Have to have this as well as previous one
  
          # Header
          lbl_header = Label(top_frame)
          lbl_header.config(text='Admit Vehicle', font='helvetica 32 bold')
  
          # Grid positioning for top frame
          top_frame.grid_rowconfigure(0, minsize=150)  # Make row 150 pixels high
          top_frame.grid(row=0)
  
          # Within Frame
          lbl_carpark_icon.grid(row=0, column=0, padx=10)
          lbl_header.grid(row=0, column=1, padx=20)
  
      def middle(self):
          # Frame to contain other widgets
          mid_frame = Frame(self.master)
  
          # Label - Car Make
          lbl_make = Label(mid_frame)
          lbl_make.config(text='Make')  # Presentation
  
          # Label - Car  Model
          lbl_model = Label(mid_frame)
          lbl_model.config(text='Model')
  
          # Label - Colour
          lbl_colour = Label(mid_frame)
          lbl_colour.config(text='Colour')
  
          # Label - Registration
          lbl_reg = Label(mid_frame)
          lbl_reg.config(text='Registration')
  
          # Label - Spaces
          lbl_spc = Label(mid_frame)
          lbl_spc.config(text='Spaces')
  
          # Text Entry - Make
          self.make = StringVar(mid_frame)
          txt_make = Entry(mid_frame)
          txt_make.config(textvariable=self.make, width=20)
  
          # Text Entry - Model
          self.model = StringVar(mid_frame)
          txt_model = Entry(mid_frame)
          txt_model.config(textvariable=self.model, width=20)
  
          # Text Entry - Colour
          self.colour = StringVar(mid_frame)
          txt_colour = Entry(mid_frame)
          txt_colour.config(textvariable=self.colour, width=20)
  
          # Text Entry - Registration
          self.reg = StringVar(mid_frame)
          txt_reg = Entry(mid_frame)
          txt_reg.config(textvariable=self.reg, width=20)
  
          # Label for number of space available (WILL BE UPDATED)
          self.num_spaces = IntVar(mid_frame)
          self.num_spaces.set = 0
          lbl_num_spaces = Label(mid_frame)
          lbl_num_spaces.config(textvariable=self.num_spaces, bg='yellow')
  
          # Display
          mid_frame.grid_columnconfigure(0, minsize=100)  # Make row 150 pixels high
          mid_frame.grid(row=1, sticky='w')
  
          # Row 0
          lbl_make.grid(row=1, column=0)
          txt_make.grid(row=1, column=1)
          lbl_spc.grid(row=1, column=2)
          lbl_num_spaces.grid(row=1, column=3, sticky='w')
  
          # Row 1
          lbl_model.grid(row=2, column=0)
          txt_model.grid(row=2, column=1, padx='10')
  
          # Row 2
          lbl_colour.grid(row=3, column=0)
          txt_colour.grid(row=3, column=1, padx='10')
  
          # Row 3
          lbl_reg.grid(row=4, column=0)
          txt_reg.grid(row=4, column=1, padx='10')
  
      def bottom(self):
          # Frame for bottom section
          bottom_frame = Frame(self.master)
  
          # Grid reference for bottom frame
          bottom_frame.grid(row=2)
  
          # Guidance message (WILL BE UPDATED)
          self.useful_msg = StringVar(bottom_frame)
          self.useful_msg.set("Enter your vehicle details")
          self.lbl_msg = Label(bottom_frame)  # Use self so we can change config at
          self.lbl_msg.config(textvariable=self.useful_msg, fg='red', width=20)
  
          # Admit Button
          btn_admit = ttk.Button(bottom_frame)
          btn_admit.config(text='Admit Vehicle')
          btn_admit.bind('&lt;Button-1&gt;', self.admit)
  
          # Show Vehicles Button
          btn_show = ttk.Button(bottom_frame)
          btn_show.config(text='Show Vehicles In Car Park')
          btn_show.bind('&lt;Button-1&gt;', self.show)
  
          # Within bottom_frame
          # row 0
          self.lbl_msg.grid(row=0, column=0)
  
          # row 1
          btn_admit.grid(row=1, column=0, sticky='e')
          btn_show.grid(row=1, column=1, sticky='e')
  
      def admit(self, event):
          self.useful_msg.set("Vehicle Admitted")
  
      def show(self, event):
          self.new_window = Toplevel(self.master)
          self.app = ShowCarsGui(self.new_window)
  </code></pre>
  
  <p>___ This is where ShowCarsGui() is ____</p>
  
  <pre><code>def main():
      root = Tk()
      CarParkGui(root)
      root.mainloop()
  
  
  main()
  </code></pre>