title: How to call multiple buttons together in Tkinter
body: <p>I'm trying to create a window with 3 buttons. When a user clicks on one of the buttons, the assigned function is called. Here is my code, I tried everything from what I read in the documentation, but I can't seem to get over it!</p>
  <p>I also added the functions called by the program, they work perfectly, just adding them for reference. Also, the buttons() function is called only one time and it's a simple call without argument.</p>
  <pre><code>def buttons():
      root.geometry('1000x1000')
  
      btncreation = tkinter.Button(root, text='Order by Creation',
                                   command=creation)
      btncreation.pack()
  
      btnmodified = tkinter.Button(root, text='Order by Last Modified',
                                   command=lastmodified)
      btnmodified.pack()
  
      btnaccessed = tkinter.Button(root, text='Order by Last Accessed',
                                   command=lastaccessed)
      btnaccessed.pack()
  
  
  def creation():
      lst.sort(key=os.path.getctime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  
  
  def lastmodified():
      lst.sort(key=os.path.getmtime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  </code></pre>
  <p>Functions called by buttons:</p>
  <pre><code>def lastaccessed():
      lst.sort(key=os.path.getatime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  </code></pre>
  <p>Also, please, please, refrain from formatting answers on my question. I just want some honest to god help and not 5 comments on how to &quot;better format my question&quot;. If you need more info, I'll be glad to give it. But I'm not answering salty comments on the formatting :)</p>
  <pre><code>import os
  import tkinter.filedialog
  import pathlib
  from os import rename
  from tkinter import simpledialog
  import getpass
  import tkinter as tk
  
  root = tkinter.Tk()
  
  # File types list
  ftypes = [
      ('Python code files', '*.py'),
      ('Perl code files', '*.pl;*.pm'),
      ('Java code files', '*.java'),
      ('C++ code files', '*.cpp;*.h'),
      ('Text files on mac', '*.rtf'),
      ('Text files', '*.txt'),
      (&quot;PDF files&quot;, &quot;*.pdf&quot;),
      ('All files', '*'),
  ]
  
  
  # The function renames and relocates selected files depending on the sorting selected
  def creation():
      lst.sort(key=os.path.getctime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  
  
  def lastmodified():
      lst.sort(key=os.path.getmtime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  
  
  def lastaccessed():
      lst.sort(key=os.path.getatime)
      num = 1
      for line in lst:
          dst = newpath + name + str(num) + suffix
          rename(line, dst)
          num += 1
  
  
  def hide(root):
      root.withdraw()
  
  
  def show(root):
      root.update()
      root.deiconify()
  
  
  def buttons():
      root.geometry('1000x1000')
  
      btncreation = tkinter.Button(root, text='Order by Creation',
                                   command=creation)
      btncreation.pack()
  
      btnmodified = tkinter.Button(root, text='Order by Last Modified',
                                   command=lastmodified)
      btnmodified.pack()
  
      btnaccessed = tkinter.Button(root, text='Order by Last Accessed',
                                   command=lastaccessed)
      btnaccessed.pack()
  
  
  
  
  hide(root)
  
  # Window to select files to order
  filez = tkinter.filedialog.askopenfilenames(title='Select files to rename (must be all of the same type!)')
  
  # List populated with file names
  lst = list(filez)
  
  # Saves the extension of the selected files
  suffix = pathlib.Path(lst[0]).suffix
  
  # Window to get user input on file naming
  
  # Asks user for file names, while loop won't break if no name is given
  USER_INP = simpledialog.askstring(title=&quot;File Names&quot;,
                                    prompt=&quot;Name your files:&quot;)
  
  while USER_INP == '':
      USER_INP = simpledialog.askstring(title=&quot;File Names&quot;,
                                        prompt=&quot;Name your files:&quot;)
  
  # Gets username for path use
  username = getpass.getuser()
  
  name = USER_INP
  
  # Asks user for folder name, while loop won't break if no name is given
  USER_INP2 = simpledialog.askstring(title=&quot;Folder Name&quot;,
                                     prompt=&quot;Name your folder:&quot;)
  
  while USER_INP2 == '':
      USER_INP2 = simpledialog.askstring(title=&quot;Folder Name&quot;,
                                         prompt=&quot;Name your folder:&quot;)
  
  foldername = USER_INP2
  
  # Creates new folder for ordered files, if folder exists, it uses it
  newpath = r'/Users/' + username + '/Desktop/' + foldername + '/'
  if not os.path.exists(newpath):
      os.makedirs(newpath)
  
  buttons()
  
  root.mainloop()
  </code></pre>