Ticket UUID: | 2d24591c3ba423effc2d9e92dac3b2a736ed295b | |||
Title: | Tkinter -postoffset not working for TCombobox Python 3.8 | |||
Type: | Bug | Version: | Tcl 8.6.9 | |
Submitter: | Sveti007 | Created on: | 2020-06-30 07:43:08 | |
Subsystem: | 22. Style Engine | Assigned To: | bll | |
Priority: | 5 Medium | Severity: | Important | |
Status: | Closed | Last Modified: | 2020-07-02 19:32:43 | |
Resolution: | Fixed | Closed By: | bll | |
Closed on: | 2020-07-02 19:32:43 | |||
Description: |
Doing a configuration of the tkinter combobox for the dropdown list with: style = ttk.Style() style.configure('TCombobox', postoffset=(0,0,width,0)) results in no changing of the combobox. In Python 2.7.16 or generally in python 2 this functionality works well. Please see the sample source-code: import tkinter as tk import tkinter.ttk as ttk import tkinter.font as tkfont def on_combo_configure(event,fruit): #font = tkfont.nametofont(str(event.widget.cget('font'))) fontstring = event.widget.cget('font') font = tkfont.nametofont('TkDefaultFont') font.configure(family=fontstring.string.split(" ")[0]) font.configure(size=fontstring.string.split(" ")[1]) maxelemfromList = max(enumerate(fruit), key=lambda x: len(x[1]))[1] width = font.measure(maxelemfromList + "0") - event.width style = ttk.Style() style.configure('TCombobox', postoffset=(0,0,width,0)) root = tk.Tk() root.title("testing the combobox") root.geometry('500x500+50+50') ownfont = tkfont.Font(family="Verdana",size=13) root.option_add("*TCombobox*Listbox*Font", ownfont) fruit = ['apples are the best', 'bananas are better', 'sveti\'s ideas are the best','nice try','z','#'] #c = AutoCombobox(root, values=fruit, width=10, textvariable="Test Variable") c = ttk.Combobox(root, values=fruit, width=5, textvariable="Test Variable",font="Verdana 13") #c = ttk.Combobox(root, values=fruit, width=10, textvariable="Test Variable") #c.bind('<<Button-1>>', lambda e: on_combo_configure(e, fruit)) c.bind('<Configure>', lambda e: on_combo_configure(e, fruit)) c.pack() root.mainloop() | |||
User Comments: |
fvogel added on 2020-07-02 03:53:25:
Merged in core-8-6-branch and trunk. fvogel added on 2020-07-01 19:39:22: Reviewed. In a nutshell the issue is that the -postoffset option is not taken into account unless the ttk::combobox also has -style. The fix is fine for me: if no style is defined, use the default style. bll added on 2020-06-30 16:22:15: You can actually just explicitly set the style to 'TCombobox', then you don't have to create a new style. ttk::combobox .cb -style TCombobox bll added on 2020-06-30 16:12:51: Bugfix branch created: bug-2d24591c Assigning to fvogel for review. bll added on 2020-06-30 16:02:41: Confirmed. There is a bug where it does not work on the default combobox style. Workaround: set a style for your combobox. package require Tk set ::x bbb ttk::combobox .cb -values {aaa bbb ccc ddd eee fff ggg hhh iii} \ -textvariable ::x -style My.TCombobox ttk::style configure My.TCombobox -postoffset {50 50 50 50} puts "A: [ttk::style lookup My.TCombobox -postoffset]" pack .cb The following lines should be added: library/ttk/combobox.tcl: set style [$cb cget -style] + if { $style eq {} } { + set style TCombobox + } |
