0

When I make a combobox in tkinter and click the arrow to select a value then the font size of the values is very less. When I change the font size then the font size of text in the entry box becomes bigger but the font size of the values in the selection section stays the same. How can I change the size of the values in the selection section?

from tkinter import *
from tkinter import ttk

WIDTH, HEIGHT = 1000, 300

root = Tk()

root.geometry(f"{WIDTH}x{HEIGHT}")

def createDropBox(master, dropBoxData, fg, bg, fontSize):
    ttk.Style().configure("style1.TCombobox", foreground = fg, background = bg)
    dropBox = ttk.Combobox(master, values = dropBoxData, style = "style1.TCombobox", font = ("", fontSize), width = 60)
    return dropBox

values = ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
dropBox = createDropBox(root, values, "blue", "white", 20)
dropBox.place(x = 20, y = 20)

root.mainloop()

2 Answers 2

2

You can add a tkinter option to increase the font for list boxes within combo boxes. Add this to your code right before root.mainloop():

from tkinter.font import Font
font = Font(family = "Helvetica", size = 20)
root.option_add("*TCombobox*Listbox*Font", font)
3
  • where does the Font Function come from? from tkinter.font or something?
    – Ved Rathi
    Jan 19, 2021 at 15:56
  • You have to add this to your import statements: from tkinter.font import Font
    – DapperDuck
    Jan 19, 2021 at 15:58
  • @VedRathi Yeah tkinter.font
    – DapperDuck
    Jan 19, 2021 at 15:59
1

I had a lot of trouble changing all the font sizes used by tkInter widgets (they are all too small for my high resolution screen). Eventually I found that this bit of code does it:

import tkFont
tk = Tkinter.Tk()
for f in tk.splitlist(tk.call("font", "names")):
    tkFont.nametofont(f).configure(size=10)

You need to do this before you create any tkInter widgets. If you want to change just some of the font sizes, print the result of tk.splitlist(tk.call("font", "names")) and experiment changing them one at a time to see which ones your widget uses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.