DearPyGui
DearPyGui copied to clipboard
Unable to bind theme to modal windows
Version of Dear PyGui
Version: 2.0.0 Operating System: Windows 10
My Issue/Question
Binding theme to modal window doesn't seem to work.
To Reproduce
This minimal code :
import dearpygui.dearpygui as dpg
from time import sleep
from random import randint
dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()
global_theme = None
with dpg.theme() as g_theme:
global_theme = g_theme
with dpg.theme_component(dpg.mvAll, enabled_state=True):
dpg.add_theme_color(dpg.mvThemeCol_TitleBgActive, (200,200,200), category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_WindowBg, (225,225,225), category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_Text, (100, 100, 100), category=dpg.mvThemeCat_Core)
dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 6, category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_Button, (200,200,200), category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, (200, 200, 200), category=dpg.mvThemeCat_Core)
dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, (200, 200, 200), category=dpg.mvThemeCat_Core)
def rand_me():
dpg.set_value("number_text", str(randint(0,100)))
def button_callback():
dpg.show_item("windowblocker")
sleep(2)
dpg.hide_item("windowblocker")
dpg.bind_theme(global_theme)
with dpg.window(label="Example Window", tag="mainwindow"):
dpg.add_button(label="Open modal", callback=button_callback)
dpg.add_button(label="Gen nb", callback=rand_me)
with dpg.group(horizontal=True):
dpg.add_text("Number : ")
dpg.add_text(label="", tag="number_text")
with dpg.window(modal=True, no_close=True, no_title_bar=True, show=False, tag="windowblocker"): # One can try removing modal=True and see the theme binding will work
dpg.add_text("The theme isn't bound here !!")
dpg.bind_item_theme("windowblocker", global_theme) # <---- BINDING HERE !!!
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
Expected behavior
The modal window theme should be the one used with dpg.bind_item_theme.
Screenshots/Video
Expected theme (regular window)
Theme in modal window
Hi, this is not a bug, indeed you need to set mvThemeCol_PopupBg instead of mvThemeCol_WindowBg, because (if I got it right) modals in ImGui are treated as a "subtype" of popups