Reputation: 325
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()
Upvotes: 0
Views: 1611
Reputation: 532
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.
Upvotes: 1
Reputation: 2874
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)
Upvotes: 2