Tk Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
19:32 Closed ticket [2d24591c]: Tkinter -postoffset not working for TCombobox Python 3.8 plus 4 other changes artifact: a226e5da user: bll
03:53 Ticket [2d24591c]: 3 changes artifact: 612a2ab1 user: fvogel
merge core-8-6-branch ; fix [2d24591c3b] -postoffset with default style. check-in: 45f035b1 user: fvogel tags: trunk
19:39 Ticket [2d24591c] Tkinter -postoffset not working for TCombobox Python 3.8 status still Open with 5 other changes artifact: 4ed491f9 user: fvogel
16:22 Ticket [2d24591c]: 3 changes artifact: aaf434cf user: bll
16:12 Ticket [2d24591c]: 4 changes artifact: 5aa8e07c user: bll
16:02 Ticket [2d24591c]: 3 changes artifact: c2be74d9 user: bll
07:43 New ticket [2d24591c]. artifact: 78520b72 user: Sveti007

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
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")
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))

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:

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:

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
+    }