title: How to change font to bold/underline/italics in Python Tkinter listbox?
body: <p>How do I change the font style of an item in a listbox? I assumed it would use <code>listbox[i].itemconfig()</code>, but <a href="https://kite.com/python/docs/Tkinter.Canvas.itemconfig" rel="nofollow noreferrer">THIS</a> implies font style is not an option.</p>
  
  <p>I also read <a href="https://mail.python.org/pipermail/python-list/2008-September/484117.html" rel="nofollow noreferrer">THIS</a>, which implies you have to first get the font of the item, then change it and set it to the new font. But how do I do this with a single item in a listbox? </p>
  
  <p>I am trying to have a button to set the selected item in a listbox as a 'master' (not important what that means), which for these purposes just needs to be highlighted in some way (preferably not with foreground/background/whatever colors). Below is my attempt, which does not at all work, because it is incomplete. I am unsure how to interact with the fonts of specific items in a listbox. Please feel free to offer better approaches.</p>
  
  <p>I apologize for not providing more or better example code. I do not know how to attempt this. I am also using <a href="https://www.tcl.tk/man/tcl8.5/TkCmd/font.htm#M28" rel="nofollow noreferrer">THIS</a> as a reference. (I am having a hard time understanding <code>tkFont</code> as a package, and why/how it should be used over <code>tk.font</code>...)</p>
  
  <pre><code>def set_master(self):
      the_selection = self.the_listbox.curselection()
      for the_index, the_item in enumerate(self.the_listbox):
          f = tkFont.Font(font=the_item.cget("font"))
  
          if int(the_selection) == int(the_index):
              f.configure(underline=True, weight='bold', slant='italic')
          else:
              f.configure(underline=False, weight='normal', slant='roman')
  
          #the_item.set_font(f)  &lt;--This is pseudocode
      return
  </code></pre>