Change width of tk Combobox dropdown scrollbar

纵然是瞬间 提交于 2020-06-01 05:14:10

问题


Is it possible to change the width of a tk Combobox scrolldown bar in python 2.7? I'm not talking about the combobox width, but rather the scrollbar width on the combobox that appears when the combobox is active. For example:

self.cmbSortOrder=ttk.Combobox(self.frame2, value=l, textvariable=self.SortOrder)
self.cmbSortOrder.bind("<<ComboboxSelected>>", self.reloadList)
self.cmbSortOrder.pack(side=LEFT)

回答1:


you can do it using configure(): This class is used to manipulate the style database.

Syntax:

configure(style, query_opt=None, **kw)

Query or set the default value of the specified option(s) in style.

Each key in kw is an option and each value is a string identifying the value for that option.

For example, to change every default button to be a flat button with some padding and a different background color do:

ttk.Style().configure("TButton", padding=6, relief="flat",background="#ccc")

in your case you can do:

from Tkinter import Tk
import ttk
root = Tk()

dropdown_width = 100
style = ttk.Style()
style.configure('TCombobox', postoffset=(0, 0, dropdown_width, 0))

value_list = ['list value 1', 'list value 2']
c = ttk.Combobox(root, values=value_list)
c.pack()

root.mainloop()




回答2:


The Combobox widget leverages the Scrollbar widget, thus changing the style of the Scrollbar widget will be observable by instances of the Combobox widget. A crude example below shows this:

# Create a style instance
style = ttk.Style()

# Specify style the preference(s) for combo box widgets
style.configure( 'TCombobox', arrowsize=25 )

# Alter the template properties of the scroll bar to affect the Combobox widget
style.configure( 'Vertical.TScrollbar', width=22 )
style.configure( 'Vertical.TScrollbar', arrowsize =22 )
style.configure( 'Vertical.TScrollbar', arrowsize =22 ) 


来源:https://stackoverflow.com/questions/59718769/change-width-of-tk-combobox-dropdown-scrollbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!