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

ttk.Checkbutton OSError #143

Closed
aatambo opened this issue Jan 17, 2022 · 13 comments
Closed

ttk.Checkbutton OSError #143

aatambo opened this issue Jan 17, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@aatambo
Copy link

aatambo commented Jan 17, 2022

Run this code and you will find an OSError: cannot open resource

import tkinter as tk
import ttkbootstrap as ttk

root = tk.Tk()

c1 = ttk.Checkbutton(root, text='music')
c1.grid ()

root.mainloop()

N/B : If i add bootstyle='success-round-toggle' it works
What might be wrong? Why does it not work without a bootstyle configuration?
I'm using manjaro linux incase it might be helpful.

@israel-dryer
Copy link
Owner

Can you paste the exact error you are getting?

Can you give me a few more pieces of information:

  • python version
  • ttkbootstrap version

Do you get the same error if you do not import tkinter and instead used ttk.Window to create the root?

@aatambo
Copy link
Author

aatambo commented Jan 17, 2022

python version 3.9.7
ttkbootstrap 1.5.0

I get the same errot still with ttk.window()

import ttkbootstrap as ttk
from ttkbootstrap.constants import *

root = ttk.Window()
root.geometry('800x500')


c = ttk.Checkbutton(root)
c.grid()

root.mainloop()

This is the error:

Traceback (most recent call last):
File "/home/dev-reflex/Desktop/Laboratory/zzz.py", line 9, in
c = ttk.Checkbutton(root)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/ttkbootstrap/style.py", line 4825, in init
ttkstyle = Bootstyle.update_ttk_widget_style(
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/ttkbootstrap/style.py", line 4911, in update_ttk_widget_style
builder_method(builder, widget_color)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/ttkbootstrap/style.py", line 3983, in create_checkbutton_style
images = self.create_checkbutton_assets(colorname)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/ttkbootstrap/style.py", line 4053, in create_checkbutton_assets
fnt = ImageFont.truetype("FreeSerif.ttf", 130)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/PIL/ImageFont.py", line 844, in truetype
return freetype(font)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/PIL/ImageFont.py", line 841, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/home/dev-reflex/.virtualenvs/tK/lib/python3.9/site-packages/PIL/ImageFont.py", line 193, in init
self.font = core.getfont(
OSError: cannot open resource

@israel-dryer
Copy link
Owner

Here is what I'm getting with other tests >>

Windows 11:

Code_XYzgHgx7R3

Raspberry Pi OS:

mstsc_z9rYznrAun

Linux Ubuntu via replit.it

msedge_UcRrhhbY1k

@israel-dryer
Copy link
Owner

@aatambo, can you show the image of it working with the bootstyle? I'm confused why it would work at all with that error message.

@aatambo
Copy link
Author

aatambo commented Jan 17, 2022

Does that mean it is either an Os related issue or python version?

@israel-dryer
Copy link
Owner

Does that mean it is either an Os related issue or python version?

I'm not sure. From the error, it appears that it is having trouble finding the FreeSerif font, but that wouldn't make sense if you say it is working with a bootstyle. I'm going to download the OS and try it out. I'm curious about it anyway. I'll see if I can get the same error to show up. Might be a day or so as I have to work.

@aatambo
Copy link
Author

aatambo commented Jan 17, 2022

with bootstyle
with_bootstyle

without bootstyle
without_bootstyle

@israel-dryer
Copy link
Owner

ok, for whatever reason, the FreeSerif font is not installed in that distribution of Manjaro. Perhaps it's a minimal install version? The reason that the round-toggle works is because it does not use a font to render the button. The regular checkbox draws a checkmark using the FreeSerif font (on Linux) onto an image which displays in the button.

In the short term, you can fix by installing the FreeSerif font. I'm not familiar enough with Arch Linux to know how to do that. In the meantime, I'll look into adding another font check (perhaps the Noto family) so that it works with this distribution out-of-the-box.

@aatambo
Copy link
Author

aatambo commented Jan 17, 2022

Okay thanks for your good work with ttkbootstrap.
Shall I close the issue now?

@israel-dryer
Copy link
Owner

You can leave it open until I resolve the font issue with that OS

@israel-dryer
Copy link
Owner

It's not my favorite choice, but I think I can make it work by adding the fallback font of DejaVuSans.ttf

VirtualBoxVM_sCPdOpzgxr

israel-dryer added a commit that referenced this issue Jan 18, 2022
@israel-dryer israel-dryer added the bug Something isn't working label Jan 18, 2022
@israel-dryer
Copy link
Owner

I was able to test this fix successfully on a Monjaro installation with version 1.5.1 using the new fallback font.

@aatambo
Copy link
Author

aatambo commented Jan 18, 2022

Cool thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants