Giter Club home page Giter Club logo

Comments (6)

Neoakay005 avatar Neoakay005 commented on June 16, 2024 4

Desktop (please complete the following information):

ttkbootstrap Version = 1.10.1 OS: Windows 11 Pro

Describe the bug

image

When working on a PC with Norwegian locale, DatePickerDialog throws a "local.Error", failing the import of ttkboostrap. Norwegian locale contains non-ASCII characters "å", which is not accepted in setting the locale in line 566 of \ttkbootstrap\dialogs\dialogs.py".

To Reproduce

Set computer region to Norway and import ttkbootstrap.

Expected behavior

No response

Screenshots

No response

Additional context

No response

I tried and tried and figure out, solve it just in a simple way:

  1. Just open up the dialogs.py in folder:
    "C:\Users"user"\AppData\Local\Programs\Python\Python312\Lib\site-packages\ttkbootstrap\dialogs\dialogs.py", line 566

  2. Overwrite this line
    locale.setlocale(locale.LC_ALL, locale.setlocale(locale.LC_TIME, ""))
    with
    "tr_TR.utf8" (but you can overwrite as default with "en_EN.utf8")
    locale.setlocale(locale.LC_ALL, locale.setlocale(locale.LC_TIME, "tr_TR.utf8"))

and everything runs without any problem.

from ttkbootstrap.

Lore-Gaviano avatar Lore-Gaviano commented on June 16, 2024 1

@Neoakay005's solution works. Thank you very much. However in case I wanna share my project, the receivers would need to execute the same changes in their own local package. This could potentially represent an annoyance. Perhaps it could be worth making a similar change in the repo too.
Thanks!

from ttkbootstrap.

rdbende avatar rdbende commented on June 16, 2024 1

Perhaps it could be worth making a similar change in the repo too.

Then please reopen this issue. Although there isn't much activity on the project lately, it's better to leave unresolved issues open.

from ttkbootstrap.

ismaelink avatar ismaelink commented on June 16, 2024

I'm not sure if my response will help you, but I've had a similar error in the past that had the same root cause as your error, which, in this case, is located in the 'dialogs.py' file at line 566. I believe that if you adapt the solution from that issue to yours, it may resolve your problem.

Based on the given link, do something like this:

set_locale_to_posix()
# Here would be all the code that uses formatting according to your preferred locale
# ....
set_locale_to_system_default()

I recommend creating functions that handle this entire process automatically, avoiding code repetition. Try doing this and then provide some feedback. Good luck! 😸

from ttkbootstrap.

Lore-Gaviano avatar Lore-Gaviano commented on June 16, 2024

Thank you for your answer, but I believe the solution may not be applicable, because the error occurs exactly the same.

import locale 
def set_locale_to_posix():
    locale.setlocale(locale.LC_ALL, "C")

def set_locale_to_system_default():
    # This part was taken from line 566 of the "dialogs.py" file present in the "ttkbootstrap" library.
    locale.setlocale(locale.LC_ALL, locale.setlocale(locale.LC_TIME, "nb_NO"))

set_locale_to_posix()
import ttkbootstrap as ttk
set_locale_to_system_default()

The problem comes from the fact that locale.setlocale(locale.LC_TIME, "")) in line 566 returns "('Norwegian Bokmål_Norway', '1252')" and the letter "å" can't be passed to locale.setlocale(locale.LC_ALL, "Norwegian Bokmål_Norway").

I have been looking into changing the default locale to something of my choice from python, to import ttkbootstrap and reset it to Norwegian at the end of the script.

I don't really have any operation to do with a particular date format, I just need to import the model, but that is when the error is raised.

from ttkbootstrap.

mmebsout avatar mmebsout commented on June 16, 2024

I got the same here and I'm not Norwegian

ttkbootstrap version 1.10.1

(venv) my_project % locale
LANG=""
LC_COLLATE="C"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

test.py

import ttkbootstrap as tb

output :

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    import ttkbootstrap as tb
  File "venv/lib/python3.10/site-packages/ttkbootstrap/__init__.py", line 3, in <module>
    from ttkbootstrap.widgets import *
  File "venv/lib/python3.10/site-packages/ttkbootstrap/widgets.py", line 14, in <module>
    from ttkbootstrap.dialogs import Querybox
  File "venv/lib/python3.10/site-packages/ttkbootstrap/dialogs/__init__.py", line 1, in <module>
    from ttkbootstrap.dialogs.dialogs import *
  File "venv/lib/python3.10/site-packages/ttkbootstrap/dialogs/dialogs.py", line 536, in <module>
    class DatePickerDialog:
  File "venv/lib/python3.10/site-packages/ttkbootstrap/dialogs/dialogs.py", line 566, in DatePickerDialog
    locale.setlocale(locale.LC_ALL, locale.setlocale(locale.LC_TIME, ""))
  File ".pyenv/versions/3.10.3/lib/python3.10/locale.py", line 620, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Platform: Apple M1 - Ventura - 13.6.1 (22G313)

from ttkbootstrap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.