title: Hiding TreeView Columns In Tkinter
body: <p>I've created a TreeView but I want to be able to hide certain columns when I call specific functions. So this TreeView gets initially created but when I call a function lets say all of the columns are hidden except for [trackArtist]. How do I do this? I can sort of get it to work by rewriting parts of the TreeView  (the columns I want to appear) within the function but that seems awfully redundant. </p>
  
  <pre><code>def some_function(self):
          self.tree = ttk.Treeview(self.stationBuilderMenuMiddleFrame)
          ttk.Style().configure("displayField", background="#850664", foreground="#000000", fieldbackground="#FFFFFF")
          ysb = ttk.Scrollbar(self.stationBuilderMenu, orient=tk.VERTICAL, command=self.tree.yview)
          xsb = ttk.Scrollbar(self.stationBuilderMenu, orient=tk.HORIZONTAL, command=self.tree.xview)
          self.tree.configure(yscrollcommand=ysb.set)
          self.tree.configure(xscrollcommand=xsb.set)
  
          self.tree["columns"]=("trackNumber", "trackTitle", "artistCat", "artistDisplay", "trackArtist", "album",
                                "albumLabel", "composer", "year", "trackDuration", "albumAsin", "albumItunes", "ISRC",
                                "filename", "albumCoverName", "notes")
          self.tree.column("trackNumber", stretch=0,  anchor=N)
          self.tree.column("trackTitle", stretch=0,  anchor=N)
          self.tree.column("artistCat", stretch=0,  anchor=N)
          self.tree.column("artistDisplay", stretch=0,  anchor=N)
          self.tree.column("trackArtist", stretch=0,  anchor=N)
          self.tree.column("album", stretch=0,  anchor=N)
          self.tree.column("albumLabel", stretch=0,  anchor=N)
          self.tree.column("composer", stretch=0, anchor=N)
          self.tree.column("year", stretch=0,  anchor=N)
          self.tree.column("trackDuration", stretch=0, anchor=N)
          self.tree.column("albumAsin", stretch=0, anchor=N)
          self.tree.column("albumItunes", stretch=0, anchor=N)
          self.tree.column("filename", stretch=0,  anchor=N)
          self.tree.column("albumCoverName", stretch=0,  anchor=N)
          self.tree.column("notes", stretch=0, anchor=N)
          self.tree.heading("trackNumber", text="Track Number")
          self.tree.heading("trackTitle", text="Track Title")
          self.tree.heading("artistCat", text="Artist CAT")
          self.tree.heading("artistDisplay", text="Artist Display")
          self.tree.heading("trackArtist", text="Track Artist")
          self.tree.heading("album", text="Album")
          self.tree.heading("albumLabel", text="Album Label")
          self.tree.heading("composer", text="Composer")
          self.tree.heading("year", text="Year")
          self.tree.heading("trackDuration", text="Track Duration")
          self.tree.heading("albumAsin", text="Album ASIN")
          self.tree.heading("albumItunes", text="Album iTunes")
          self.tree.heading("ISRC", text="ISRC")
          self.tree.heading("filename", text="File Name")
          self.tree.heading("albumCoverName", text="Album Cover Filename")
          self.tree.heading("notes", text="Notes")
          self.tree.grid(in_=self.stationBuilderMenuMiddleFrame, row=0, column=0, sticky=tk.NSEW)
          ysb.grid(in_=self.stationBuilderMenuMiddleFrame, row=0, column=1, sticky=tk.NS)
          xsb.grid(in_=self.stationBuilderMenuMiddleFrame, row=1, column=0, sticky=tk.EW)
          self.stationBuilderMenuMiddleFrame.rowconfigure(0, weight=1)
          self.stationBuilderMenuMiddleFrame.columnconfigure(0, weight=1)
  </code></pre>
  
  <p>This is the hack code I've thrown together. Doesn't work very well.</p>
  
  <pre><code>def some_other_function(self):
      # things happen
      # inefficient code below
      self.tree["columns"]=("artistCat", "artistDisplay")
      self.tree.column("artistCat", stretch=0,  anchor=N)
      self.tree.column("artistDisplay", stretch=0,  anchor=N)
      self.tree.heading("artistCat", text="Artist CAT")
      self.tree.heading("artistDisplay", text="Artist Display")
  
  class StationBuilder():
      def __init__(self, master, importTree):
          self.importTree = importTree
          self.stationBuilderMenu = master
          self.stationBuilderMenu = Toplevel(master)
          self.stationBuilderMenuTopFrame = Frame(self.stationBuilderMenu, bg="#BFC0C2", bd=1, relief=RIDGE)
          self.stationBuilderMenuMiddleFrame = Frame(self.stationBuilderMenu)
          self.stationBuilderMenuBottomFrame = Frame(self.stationBuilderMenu, bg="#BFC0C2", bd=1, relief=RIDGE)
          self.stationBuilderMenuRightFrame = Frame(self.stationBuilderMenu, bg="#BFC0C2", bd=1, relief=RIDGE, width=300)
          self.stationBuilderMenu.wm_title("AccuAdmin - toStationBuilder")
          self.stationBuilderMenu.configure(background="#BFC0C2")
          self.currentTrack = 0
          self.currentState = 0
          self.artistObjectId = ""
          self.albumObjectId = ""
          self.composerObjectId = ""
          self.trackObjectId = ""
          self.treeId = ""
          self.states = [self.search_artist, self.search_album, self.search_composer, self.search_track]
  
          self.match = Button(self.stationBuilderMenuBottomFrame, text="Match", highlightbackground="#BFC0C2",
                              command=self.exists)
          self.createNewObject = Button(self.stationBuilderMenuBottomFrame, text="", highlightbackground="#BFC0C2",
                                        command=self.create_new_object)
          self.currentObject = Label(self.stationBuilderMenuTopFrame, text="", font=("default", 50), bg="#BFC0C2",
                                     fg="#FFFFFF")
          self.currentlyProcessedTrackHeading = Label(self.stationBuilderMenuRightFrame, text="- Current Track -",
                                                      bg="#BFC0C2")
          self.currentlyProcessedTrack = Label(self.stationBuilderMenuRightFrame, text="", bg="#BFC0C2")
  
          self.create_potential_match_display()
  
          self.stationBuilderMenuBottomFrame.pack(side=BOTTOM, fill=X)
          self.stationBuilderMenuTopFrame.pack(side=TOP, fill=X)
          self.stationBuilderMenuRightFrame.pack(side=RIGHT, fill=Y)
          self.stationBuilderMenuMiddleFrame.pack(side=LEFT, fill=BOTH)
          self.currentObject.pack(side=LEFT, padx=(25, 0))
          self.currentlyProcessedTrackHeading.pack(side=TOP)
          self.currentlyProcessedTrack.pack(side=TOP)
          self.match.pack(side=RIGHT, padx=(0, 25))
          self.createNewObject.pack(side=LEFT, padx=(25, 0))
  
          self.states[self.currentState](importedTracks[self.currentTrack])
          self.tree.bind("&lt;&lt;TreeviewSelect&gt;&gt;", self.find_selection)
  </code></pre>