2

I know there are many ways to change the drop down list/list box font, my question is how could you adjust the entry field at the same time, the part circled in red. How do I make it the same size as the label next to it? In other word, how do i make the drop down arrow bigger?

label = ttk.Label(frame, text='truck id: ', anchor=w, font=bigger_font)
c = ttk.Combobox(frame, textvariable=truckID, values=['1','2','3','4'])
c['state'] = 'readonly'
root.option_add('*TCombobox*Listbox.font', bigger_font)

enter image description here

5
  • This is a little vague. What do you mean by "entry field?" Dec 14, 2018 at 19:27
  • I edited my question, hope it is more clear now
    – Aaron_Geng
    Dec 14, 2018 at 19:34
  • By Label, do you mean "Truck ID" or 1/2/3/4?
    – Miraj50
    Dec 14, 2018 at 19:36
  • @Miraj50 anyone is fine, just want to make it larger.
    – Aaron_Geng
    Dec 14, 2018 at 19:38
  • Please provide a minimal reproducible example which illustrates what you’ve tried. Dec 14, 2018 at 19:41

1 Answer 1

9

Combobox has a width attribute which lets you control its size. The width is in terms of the number of characters. So for example, if you know that your combobox entries are single digit numbers, you can set the width attribute as, say 1. Here is an example.

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
tList = ttk.Combobox(root, values=[1, 2, 3, 4, 5], state="readonly", width=1)
tList.current(0)
tList.grid(row=0, column=1, padx=10, pady=10)
root.mainloop()

enter image description here

Now see, if you change the width to 2.

enter image description here

It is exactly half the size of the combobox entry.

Basically, if you know what kind (length) of entries your combobox will contain, you can control its size.

If you want it to be taller in height, manipulate its font attribute.

tList = ttk.Combobox(root, values=[1, 2, 3, 4, 5], state="readonly", width=2, font="Verdana 16 bold")

enter image description here

4
  • Thank you, but I don't want it to be wider, I want it to be taller, in height, not in width
    – Aaron_Geng
    Dec 14, 2018 at 19:47
  • But the number displayed in that field is still small, how do you make it taller as well and also bold
    – Aaron_Geng
    Dec 14, 2018 at 19:51
  • Simple, add font attribute. For eg. ttk.Combobox(root, values=[1, 2, 3, 4, 5], state="readonly", width=1, font="Verdana 12 bold"). See new edit.
    – Miraj50
    Dec 14, 2018 at 19:53
  • @Aaron_Geng Also since you are using some bigger_font for the Label. Try using the same for the combobox as well.
    – Miraj50
    Dec 14, 2018 at 20:01

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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.