title: Using a dictionary entry as a variable in a shell command?
body: <p>For my first real project I'm using Tkinter to create a UI where, when a button is pressed, something happens.</p>
  <p>I've created the UI which works well - buttons are made and are clickable, but I want each button to have it's own unique function - this is where I get lost.</p>
  <p>I've got a nested dictionary:</p>
  <pre><code>siteDict = {1: {'app1': 'explorer', 'app2': 'firefox', 'app3': 'google-chrome', 'app4': 'edge'},
              2: {'site1': 'http://www.google.com', 'site2': 'http://www.yahoo.com', 'site3': 'http://altavista', 'site4': 'http://www.askjeeves.com', }}
  </code></pre>
  <p>And I want to pass entries from the dictionary to terminal instead of having to manually define each one like I am now:</p>
  <pre><code>def Expl_Goog():
          os.system('echo Opening Explorer and navigating to Google (http://www.google.com). Please wait.')
  </code></pre>
  <p>So instead of doing <code>echo Opening Explorer and navigating to Google (http://www.google.com). Please wait.</code> is there a way to pass 2 items from my dictionary into the terminal command? {app1} and {site1} in this example.</p>
  <p>Defining variables for ~12 things isn't terrible, but the real side of the project has the same type of dictionary but with 64 entries in each one.</p>
  <p>Here's the code I have so far, which is functional. The button click functionality is done via the &quot;command&quot; argument within the button creation -  <code>ttk.Button(self.Explorer_labelFrame, text=&quot;google&quot;, command=Expl_Goog).grid(column=0, row=0, pady=2, sticky=tk.EW)</code></p>
  <p>Built on 3.9.5</p>
  <pre><code>import tkinter as tk
  from tkinter import ttk
  import os
  
  # Dictionary to house variables
  siteDict = {1: {'app1': 'explorer', 'app2': 'firefox', 'app3': 'google-chrome', 'app4': 'edge'},
              2: {'site1': 'http://www.google.com', 'site2': 'http://www.yahoo.com', 'site3': 'http://altavista', 'site4': 'http://www.askjeeves.com', }}
  
  # Defining the action for the Tkinter button press to do
  def Expl_Goog():
          os.system('echo Opening Explorer and navigating to Google (http://www.google.com). Please wait.')
  
  # Another definition - Explorer and Yahoo
  def Expl_Yah():
          os.system('echo Opening Explorer and navigating to Yahoo (http://www.yahoo.com). Please wait.')
  
  def Fire_Goog():
          os.system('echo Opening Firefox and navigating to Google (http://www.google.com). Please wait.')
  
  def Fire_Yah():
      os.system('echo Opening Firefox and navigating to Yahoo (http://www.yahoo.com). Please wait.')
  
  # Build UI via Tkinter
  class App(tk.Tk):
      def __init__(self):
          super(App, self).__init__()
  
          self.title(&quot;Website Launcher&quot;)
          self.minsize(200, 400)
          #self.wm_iconbitmap('icon.ico')
          self.lift()
          self.attributes('-topmost', True)
          self.update()
  
          self.Explorer_labelFrame = ttk.LabelFrame(self, text=&quot;Explorer&quot;, labelanchor='n')
          self.Explorer_labelFrame.grid(column=0, row=7, padx=20, pady=40)
          
          self.Firefox_labelFrame = ttk.LabelFrame(self, text=&quot;Firefox&quot;, labelanchor='n')
          self.Firefox_labelFrame.grid(column=2, row=7, padx=20, pady=40)
  
  
          self.labels_Explorer()
          self.labels_Firefox()
  
  # Creating UI Buttons
  # &quot;command&quot; argument makes clicking the button run the terminal command defined above
      def labels_Explorer(self):
          ttk.Button(self.Explorer_labelFrame, text=&quot;google&quot;, command=Expl_Goog).grid(column=0, row=0, pady=2, sticky=tk.EW)
          ttk.Button(self.Explorer_labelFrame, text=&quot;yahoo&quot;, command=Expl_Yah).grid(column=0, row=1, pady=2, sticky=tk.EW)
          ttk.Button(self.Explorer_labelFrame, text=&quot;altavista&quot;).grid(column=0, row=2, pady=2, sticky=tk.EW)
          ttk.Button(self.Explorer_labelFrame, text=&quot;askjeeves&quot;).grid(column=0, row=3, pady=2, sticky=tk.EW)
  
      def labels_Firefox(self):
          ttk.Button(self.Firefox_labelFrame, text=&quot;google&quot;, command=Fire_Goog).grid(column=0, row=0, pady=2, sticky=tk.EW)
          ttk.Button(self.Firefox_labelFrame, text=&quot;yahoo&quot;, command=Fire_Yah).grid(column=0, row=1, pady=2, sticky=tk.EW)
          ttk.Button(self.Firefox_labelFrame, text=&quot;altavista&quot;).grid(column=0, row=2, pady=2, sticky=tk.EW)
          ttk.Button(self.Firefox_labelFrame, text=&quot;askjeeves&quot;).grid(column=0, row=3, pady=2, sticky=tk.EW)
  
  app = App()
  app.mainloop()
  </code></pre>