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

User warning for equal title font color and menu background color when the latter is set to (0, 0, 0) #473

Closed
DKNorad opened this issue Oct 23, 2023 · 2 comments
Labels

Comments

@DKNorad
Copy link
Contributor

DKNorad commented Oct 23, 2023

Environment information
Describe your environment information, such as:

  • OS: Linux
  • python version: v3.11
  • pygame version: v2.5.1
  • pygame-menu version: v4.4.3

Describe the bug
While using a menubar style that calls self._check_title_color(background_menu=True) I get the following error when my Theme background_color is black (0, 0, 0).

venv/lib/python3.11/site-packages/pygame_menu/widgets/widget/menubar.py:203: UserWarning: title font color (0, 0, 0) is equal to the menu background color (0, 0, 0, 255), consider editing your Theme
  warn(

To Reproduce

import pygame_menu
from pygame_menu import Theme

menu_theme = Theme(background_color=BLACK, title_font_color=WHITE, widget_padding=5,
                   title_bar_style=pygame_menu.widgets.MENUBAR_STYLE_NONE,
                   widget_selection_effect=pygame_menu.widgets.NoneSelection(),
                   fps=60, title_font=pygame.font.Font(pygame.font.get_default_font(), 150), 
                   widget_alignment=pygame_menu.locals.ALIGN_LEFT,
                   widget_margin=(10, 0), widget_font_color=WHITE, title_offset=(10, 70))

menu = pygame_menu.Menu('Title', 800, 600, theme=menu_theme)
menu.mainloop(window)

Expected behavior
To not show the error.

Additional context
I was trying to debug the problem. "_check_title_color()" gets called 3 times and this is the output from "self._font_color" with the code above.

(0, 0, 0)
(255, 255, 255, 255)  <<<<<<< title_font_color=WHITE
(255, 255, 255, 255)   <<<<<<< title_font_color=WHITE

I can't figure out why on the first call it uses the default value of (0, 0, 0) and why it goes through it 3 times.

@DKNorad DKNorad added the bug label Oct 23, 2023
@andrew-karppinen
Copy link

Yeah,

UserWarning: title font color (0, 0, 0) is equal to the menu background color (0, 0, 0, 255), consider editing your Theme
  warn(

This code gives me an user warning:

theme = pygame_menu.Theme(background_color=(0, 0, 0), title_background_color=(178, 29, 29),
                                    widget_font_color=(255, 255, 255), widget_padding=6,title_font_color = (255,255,255),
                                    title_font_size=52,widget_font_size=38,title_bar_style = pygame_menu.widgets.MENUBAR_STYLE_UNDERLINE) #create menu theme

Error occurs if title theme is "MENUBAR_STYLE_UNDERLINE", "MENUBAR_STYLE_UNDERLINE_TITLE" or "MENUBAR_STYLE_NONE "

@DKNorad
Copy link
Contributor Author

DKNorad commented Nov 2, 2023

I found where the problem is coming from.
We are running self._menubar.set_menu(self) in menu.py:524 before we set the font variables with self._menubar.set_font() in menu.py:525. We end up running self._check_title_color() in menubar.py before we set the self._font_color in widget.py, and it takes the default value which is (0, 0, 0).

DKNorad added a commit to DKNorad/pygame-menu that referenced this issue Nov 2, 2023
Moved the .set_menu after .set_font to avoid _check_title_color before a title font color is set.
ppizarror added a commit that referenced this issue Nov 3, 2023
Avoid incorrect warning about title font color and menu background color being equal or similar |  #473
@DKNorad DKNorad closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants