israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.9k stars 381 forks source link

ColorChooserDialog cannot get result in Chinese system language #462

Closed DanDDXuanX closed 1 year ago

DanDDXuanX commented 1 year ago

Desktop (please complete the following information):

ttkbootstrap version 1.10.0 OS: Windows 11

Describe the bug

when system language is Chinese, the OK and Cancel button on ColorChooserDialog will be translate to 【确定】and【取消】,but in ColorChooserDialog.on_button_press method, it check whether the text of button is "OK", to decide output results or not (see line 561 in file dialogs/colorchooser.py). So that we can't get the result of ColorChooserDialog.__

To Reproduce

  1. in Chinese system language
  2. Go to ColorChooserDialog
  3. click 【确定】
  4. see error

Expected behavior

I override the on_button_press method (see below), and it works now. but it is evident that this approach is not robust for other system languages. Hope this will be helpful.

class ColorChooserDialog(colorchooser.ColorChooserDialog):
    def on_button_press(self, button):
        if button.cget('text') in ('OK','确定'):
            values = self.colorchooser.get_variables()
            self._result = colorchooser.ColorChoice(
                rgb=(values.r, values.g, values.b), 
                hsl=(values.h, values.s, values.l), 
                hex=values.hex
            )
            self._toplevel.destroy()            
        self._toplevel.destroy()

Screenshots

No response

Additional context

No response

DanDDXuanX commented 1 year ago

I see better solution in issue #332, and I'll close this issue.

giordanoshai commented 1 month ago

wtf,哥们,我也发现了这个问题,折腾了半天。就是不返回结果。