Combobox fontsize in tkinter

后端 未结 2 1012
野趣味
野趣味 2020-12-20 23:22

Hi I am trying to use the ttk Combobox to create a dropdown with options . While doing so i can configure the font size of the default value passed to it . But when i click

2条回答
  •  心在旅途
    2020-12-20 23:46

    The thing is that the dropdown menu of the ttk Combobox is actually a simple Tkinter Listbox so it isn't affected by the ttk style. If it would be possible to get a reference to the Listbox from the Combobox, changing the font would be easy. However, I couldn't find a way to do so in Tkinter.

    Edited as per patthoyts' very useful comment.
    What you can do is change the font for all Listboxes that are part of a Combobox using

    bigfont = tkFont.Font(family="Helvetica",size=20)
    root.option_add("*TCombobox*Listbox*Font", bigfont)
    

    That changes the font of all Listbox widgets that are part of a ttk Combobox and that are created after calling this.
    This does affect all new Comboboxes, but I assume that's what you want. If you want the new font only for this Combobox, you could choose to create this Combobox as the last widget and call self.parent.option_add("*TCombobox*Listbox*Font", bigfont) right before creating this Combobox. Then only the Listbox under this Combobox will have the new font.


    If you want all widgets to have the bigger font, you can use

    root.option_add("*Font", bigfont)
    

    or you can change the default font as described in this answer.

提交回复
热议问题