Skip to content

[Bug] Combo.update causes _tkinter.TclError: unknown color name "1234567890" if theme is Default or Default1 #4586

@nachocho

Description

@nachocho

Type of Issue (Enhancement, Error, Bug, Question)

Bug

Operating System

MacOS

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Version information can be obtained by calling sg.main_get_debug_data()

Python version: 3.10.0b4 (v3.10.0b4:2ba4b20854, Jul 9 2021, 21:56:21) [Clang 12.0.5 (clang-1205.0.22.9)]
port: tkinter
tkinter version: 8.6.11
PySimpleGUI version: 4.45.0.44
PySimpleGUI filename: /Users/Nacho/PycharmProjects/test/PySimpleGUI.py


Your Experience In Months or Years (optional)

Years Python programming experience: 3 years

Years Programming experience overall: 20 years

Have used another Python GUI Framework? Qt

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal Demos.PySimpleGUI.org
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

Detailed Description

This issue is an extension of issue #4576.
Trying to change the background color of an element to the "default" color defined in sg.DEFAULT_INPUT_ELEMENTS_COLOR after calling sg.theme('Default1') or sg.theme('Default') does not change the color for Input and Multiline elements, and throws the same error reported in issue #4576 for Combo and Listbox elements:

_tkinter.TclError: unknown color name "1234567890"

Note that I only tested those 4 elements but other elements might be affected as well.

The tkinter error is not raised with the latest published version in PyPi (at the moment 4.45.0).

Code To Duplicate

Using this first snippet of code, you can reproduce the behavior of the Input and Multiline elements not changing their background color. Clicking Change to default BG color shows the problem, while clicking Change BG color works as expected.

import PySimpleGUI as sg


sg.theme('Default1')
window = sg.Window(title='Window',
                   layout=[[sg.Input(background_color='RED', key='INPUT')],
                           [sg.Multiline(background_color='RED', key='MULTILINE')],
                           [sg.Combo(values=['YELLOW', 'BLUE', 'GREEN', 'ORANGE'], default_value='YELLOW',
                                     key='COLOR'),
                            sg.Button(button_text='Change BG color', key='CHANGE')],
                           [sg.Button(button_text='Change to default BG color', key='CHANGE_DEFAULT')],
                           [sg.CloseButton(button_text='Close')]])
while True:
    event, values = window.read()
    if event in ('Close', sg.WIN_CLOSED):
        break
    if event in ('CHANGE', 'CHANGE_DEFAULT'):
        bg_color = values['COLOR'] if event == 'CHANGE' else sg.DEFAULT_INPUT_ELEMENTS_COLOR
        for key in ('INPUT', 'MULTILINE'):
            window[key].update(background_color=bg_color)
window.close()

Using this second snippet of code you will see 2 different problems:

  1. The background color of the Combo element is not initially set as expected ONLY if sg.theme('Default1) or sg.theme('Default') is used before trying to set the combo background color initially. (This error happens even in PySimpleGUI version 4.45.0 released last year)
  2. The _tkinter.TclError: unknown color name "1234567890" error is raised when trying to update the background color of Combo and Listbox elements. (This error does not happen in PySimpleGUI version 4.45.0 released last year)
import PySimpleGUI as sg


sg.theme('Default1')
window = sg.Window(title='Window',
                   layout=[[sg.Input(background_color='RED', key='INPUT')],
                           [sg.Combo(values=['A', 'B', 'C'], background_color='RED', key='COMBO')],
                           [sg.Multiline(background_color='RED', key='MULTILINE')],
                           [sg.Listbox(values=['A', 'B', 'C'], size=(5, 8), background_color='RED', key='LISTBOX')],
                           [sg.Combo(values=['YELLOW', 'BLUE', 'GREEN', 'ORANGE'], default_value='YELLOW',
                                     key='COLOR'),
                            sg.Button(button_text='Change BG color', key='CHANGE')],
                           [sg.Button(button_text='Change to default BG color', key='CHANGE_DEFAULT')],
                           [sg.CloseButton(button_text='Close')]])
while True:
    event, values = window.read()
    if event in ('Close', sg.WIN_CLOSED):
        break
    if event in ('CHANGE', 'CHANGE_DEFAULT'):
        bg_color = values['COLOR'] if event == 'CHANGE' else sg.DEFAULT_INPUT_ELEMENTS_COLOR
        for key in ('INPUT', 'MULTILINE'):
            window[key].update(background_color=bg_color)
        for key in ('LISTBOX',):
            window[key].Widget.config(background=bg_color)
        for key in ('COMBO',):
            sg.ttk.Style().configure(f"{key}.TCombobox", fieldbackground=bg_color)
window.close()

Screenshot, Sketch, or Drawing

This screenshot shows the error of the Combo element not having its background color set:

Screen Shot 2021-08-04 at 22 04 30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions