Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Bug] sg.ColorChooserButton Unless Additional Tkinter Import #6742

Open
5 of 10 tasks
bowespublishing opened this issue Apr 12, 2024 · 1 comment
Open
5 of 10 tasks
Labels
Bug Something's not right Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ Port - TK PySimpleGUI

Comments

@bowespublishing
Copy link

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

Error/Bug

Operating System

Windows 11

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter

Versions

Python version: 3.10.11
Platform: Windows
Platform version: ('10', '10.0.22621', 'SP0', 'Multiprocessor Free')
Port: PySimpleGUI
tkinter version: 8.6.12
PySimpleGUI version: 5.0.4

Troubleshooting

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

  • Searched main docs for your problem PySimpleGUI Documenation
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demo Programs
  • None of your GUI code was generated by an AI algorithm like GPT
  • 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.com
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried running the Development Build. Your problem may have already been fixed but not released. Check Home Window for release notes and upgrading capability
  • For licensing questions please email license@PySimpleGUI.com

Detailed Description

sg.ColorChooserButton raises an Exception

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\lukeb\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1921, in call
return self.func(*args)
File "C:\Users\lukeb\AppData\Local\Programs\Python\Python310\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5016, in ButtonCallBack
color = tk.colorchooser.askcolor(parent=self.ParentForm.TKroot, color=self.default_color) # show the 'get file' dialog box
AttributeError: module 'tkinter' has no attribute 'colorchooser'

Unless you add an extra import - from tkinter import colorchooser

Code To Duplicate

def main():
    layout = [
        [sg.Push(),
         sg.In("", visible=False, enable_events=True, key='set_line_color'),
         sg.ColorChooserButton("Grid line\ncolour", size=(8, 2), target='set_line_color', border_width=1,
                               key='set_line_color_chooser'), 
         sg.Button("", size=(2, 1), disabled=True, button_color=('#000000', '#000000'), border_width=4,
                   key='colourbox') 
        ]
    ]

    window = sg.Window("Simple GUI Example", layout)

    while True:
        event, values = window.read()
        if event == sg.WINDOW_CLOSED:
            break
        elif event == 'set_line_color':
            window['colourbox'].update(button_color=(values['set_line_color'], values['set_line_color']))

    window.close()

if __name__ == "__main__":
    main()
@PySimpleGUI PySimpleGUI added Bug Something's not right Port - TK PySimpleGUI labels Apr 12, 2024
@PySimpleGUI
Copy link
Owner

Thank you for reporting this bug!
The line of code with the import was commented out in the code for some odd reason. I uncommented it and your code ran.

Added the fix in a maint release 5.0.4.5 that you can install via the Home Window (psghome).

@PySimpleGUI PySimpleGUI added the Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something's not right Done - Install Dev Build (see docs for how) See https://docs.pysimplegui.com/en/latest/documentation/installing_licensing/upgrading/ Port - TK PySimpleGUI
Projects
None yet
Development

No branches or pull requests

2 participants