主题

主题是由以下内容组成的容器:
主题组件:

主题中可以指定主题颜色/样式目标的项目类型的容器

主题颜色:

添加到主题组件并设置颜色的项

主题样式:

添加到主题组件并设置样式的项目

主题可以是:

  • 绑定为默认主题。这将在所有窗口中产生全局效果并传播。

  • 绑在一个集装箱上。如果主题中有适用的主题组件,则这将传播到其子级。

  • 如果主题中有适用的主题组件,则绑定到项类型。

主题组件必须具有指定的项目类型。这可以是 MvAll 适用于所有项目或特定项目类型。

Style和Colors项具有命名常量,并将该常量应用于其名为Item Type的组件。样式和颜色项必须具有命名类别。常量在名称中包含它们的类别。

主题颜色和样式分为以下类别:

mvThemeCat_Plots

与绘图关联的项目。由标识的样式/颜色常量 mvPlotCol_* ** * or * mvPlotStyle_** *

mvThemeCat_Nodes

与节点关联的项。由标识的样式/颜色常量 mvNodeCol_* ** * or * mvNodeStyle_** *

mvThemeCat_Core

所有其他物品都在dearpygui内。由标识的样式/颜色常量 mvThemeCol_* ** * or * mvThemeStyle_** *

默认主题(全局)

默认主题将在所有窗口中全局应用主题并传播给子窗口。

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1:
    t1 = dpg.add_input_text(default_value="some text")
    t2 = dpg.add_input_text(default_value="some text")
    with dpg.child_window(height=100):
        t3 = dpg.add_input_text(default_value="some text")
        dpg.add_input_int()
    dpg.add_input_text(default_value="some text")

with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2:
    dpg.add_input_text(default_value="some text")
    dpg.add_input_int()

with dpg.theme() as global_theme:

    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (255, 140, 23), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

    with dpg.theme_component(dpg.mvInputInt):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (140, 255, 23), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

dpg.bind_theme(global_theme)

dpg.show_style_editor()

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

集装箱传播

将主题应用于容器会将该主题传播给子容器:

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1:
    t1 = dpg.add_input_text(default_value="some text")
    t2 = dpg.add_input_text(default_value="some text")
    with dpg.child_window(height=100):
        t3 = dpg.add_input_text(default_value="some text")
        dpg.add_input_int()
    dpg.add_input_text(default_value="some text")

with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2:
    dpg.add_input_text(default_value="some text")
    dpg.add_input_int()

with dpg.theme() as container_theme:

    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (150, 100, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

    with dpg.theme_component(dpg.mvInputInt):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (100, 150, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

dpg.bind_item_theme(win1, container_theme)

dpg.show_style_editor()

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

特定于项目

如果主题包含适用的组件,则将主题应用于项将覆盖指定项上的任何先前主题。

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1:
    t1 = dpg.add_input_text(default_value="some text")
    t2 = dpg.add_input_text(default_value="some text")
    with dpg.child_window(height=100):
        t3 = dpg.add_input_text(default_value="some text")
        dpg.add_input_int()
    dpg.add_input_text(default_value="some text")

with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2:
    dpg.add_input_text(default_value="some text")
    dpg.add_input_int()

with dpg.theme() as item_theme:
    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (200, 200, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 0, category=dpg.mvThemeCat_Core)

dpg.bind_item_theme(t2, item_theme)

dpg.show_style_editor()

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

主题的优先顺序

该主题按以下顺序排列最新应用的主题的优先顺序

  1. 具体项目

  2. 继承的容器

  3. 全球

import dearpygui.dearpygui as dpg

dpg.create_context()

with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1:
    t1 = dpg.add_input_text(default_value="some text")
    t2 = dpg.add_input_text(default_value="some text")
    with dpg.child_window(height=100):
        t3 = dpg.add_input_text(default_value="some text")
        dpg.add_input_int()
    dpg.add_input_text(default_value="some text")

with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2:
    dpg.add_input_text(default_value="some text")
    dpg.add_input_int()

with dpg.theme() as global_theme:
    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (255, 140, 23), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

    with dpg.theme_component(dpg.mvInputInt):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (140, 255, 23), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

with dpg.theme() as container_theme:
    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (150, 100, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

    with dpg.theme_component(dpg.mvInputInt):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (100, 150, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core)

with dpg.theme() as item_theme:
    with dpg.theme_component(dpg.mvAll):
        dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (200, 200, 100), category=dpg.mvThemeCat_Core)
        dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 0, category=dpg.mvThemeCat_Core)

dpg.bind_theme(global_theme)
dpg.bind_item_theme(win1, container_theme)
dpg.bind_item_theme(t2, item_theme)

dpg.show_style_editor()

dpg.create_viewport(title='Custom Title', width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

禁用项目的主题

每个项目都有一个单独的禁用主题,该主题在禁用该项目时使用。禁用的主题遵循与启用的主题相同的传播规则。当项目的参数 enabled 设置为 False 该项目将使用其禁用的主题。如果未设置禁用主题,则将使用默认主题。

import dearpygui.dearpygui as dpg

dpg.create_context()
dpg.create_viewport()
dpg.setup_dearpygui()

with dpg.theme() as disabled_theme:
    with dpg.theme_component(dpg.mvInputFloat, enabled_state=False):
        dpg.add_theme_color(dpg.mvThemeCol_Text, [255, 0, 0])
        dpg.add_theme_color(dpg.mvThemeCol_Button, [255, 0, 0])

    with dpg.theme_component(dpg.mvInputInt, enabled_state=False):
        dpg.add_theme_color(dpg.mvThemeCol_Text, [255, 0, 0])
        dpg.add_theme_color(dpg.mvThemeCol_Button, [255, 0, 0])

dpg.bind_theme(disabled_theme)

with dpg.window(label="tutorial"):
    dpg.add_input_float(label="Input float", enabled=False)
    dpg.add_input_int(label="Input int", enabled=False)

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

地块标记

地块标记

mvPlotMarker_None

mvPlotMarker_Circle

mvPlotMarker_Square

mvPlotMarker_Diamond

mvPlotMarker_Up

mvPlotMarker_Down

mvPlotMarker_Left

mvPlotMarker_Right

mvPlotMarker_Cross

mvPlotMarker_Plus

mvPlotMarker_Asterisk

核心色

核心色

mvThemeCol_Text

mvThemeCol_TabActive

mvThemeCol_SliderGrabActive

mvThemeCol_TextDisabled

mvThemeCol_TabUnfocused

mvThemeCol_Button

mvThemeCol_WindowBg

mvThemeCol_TabUnfocusedActive

mvThemeCol_ButtonHovered

mvThemeCol_ChildBg

mvThemeCol_DockingPreview

mvThemeCol_ButtonActive

mvThemeCol_Border

mvThemeCol_DockingEmptyBg

mvThemeCol_Header

mvThemeCol_PopupBg

mvThemeCol_PlotLines

mvThemeCol_HeaderHovered

mvThemeCol_BorderShadow

mvThemeCol_PlotLinesHovered

mvThemeCol_HeaderActive

mvThemeCol_FrameBg

mvThemeCol_PlotHistogram

mvThemeCol_Separator

mvThemeCol_FrameBgHovered

mvThemeCol_PlotHistogramHovered

mvThemeCol_SeparatorHovered

mvThemeCol_FrameBgActive

mvThemeCol_TableHeaderBg

mvThemeCol_SeparatorActive

mvThemeCol_TitleBg

mvThemeCol_TableBorderStrong

mvThemeCol_ResizeGrip

mvThemeCol_TitleBgActive

mvThemeCol_TableBorderLight

mvThemeCol_ResizeGripHovered

mvThemeCol_TitleBgCollapsed

mvThemeCol_TableRowBg

mvThemeCol_ResizeGripActive

mvThemeCol_MenuBarBg

mvThemeCol_TableRowBgAlt

mvThemeCol_Tab

mvThemeCol_ScrollbarBg

mvThemeCol_TextSelectedBg

mvThemeCol_TabHovered

mvThemeCol_ScrollbarGrab

mvThemeCol_DragDropTarget

mvThemeCol_ScrollbarGrabHovered

mvThemeCol_NavHighlight

mvThemeCol_ScrollbarGrabActive

mvThemeCol_NavWindowingHighlight

mvThemeCol_CheckMark

mvThemeCol_NavWindowingDimBg

mvThemeCol_SliderGrab

mvThemeCol_ModalWindowDimBg

打印颜色

打印颜色

mvPlotCol_Line

mvPlotCol_LegendBg

mvPlotCol_YAxisGrid

mvPlotCol_Fill

mvPlotCol_LegendBorder

mvPlotCol_YAxis2

mvPlotCol_MarkerOutline

mvPlotCol_LegendText

mvPlotCol_YAxisGrid2

mvPlotCol_MarkerFill

mvPlotCol_TitleText

mvPlotCol_YAxis3

mvPlotCol_ErrorBar

mvPlotCol_InlayText

mvPlotCol_YAxisGrid3

mvPlotCol_FrameBg

mvPlotCol_XAxis

mvPlotCol_Selection

mvPlotCol_PlotBg

mvPlotCol_XAxisGrid

mvPlotCol_Query

mvPlotCol_PlotBorder

mvPlotCol_YAxis

mvPlotCol_Crosshairs

节点颜色

节点颜色

mvNodeCol_NodeBackground

mvNodeCol_TitleBarSelected

mvNodeCol_BoxSelector

mvNodeCol_NodeBackgroundHovered

mvNodeCol_Link

mvNodeCol_BoxSelectorOutline

mvNodeCol_NodeBackgroundSelected

mvNodeCol_LinkHovered

mvNodeCol_GridBackground

mvNodeCol_NodeOutline

mvNodeCol_LinkSelected

mvNodeCol_GridLine

mvNodeCol_TitleBar

mvNodeCol_Pin

mvNodeCol_PinHovered

mvNodeCol_TitleBarHovered

核心样式

常量

组件

mvStyleVar_Alpha

1

mvStyleVar_WindowPadding

2

mvStyleVar_WindowRounding

1

mvStyleVar_WindowBorderSize

1

mvStyleVar_WindowMinSize

2

mvStyleVar_WindowTitleAlign

2

mvStyleVar_ChildRounding

1

mvStyleVar_ChildBorderSize

1

mvStyleVar_PopupRounding

1

mvStyleVar_PopupBorderSize

1

mvStyleVar_FramePadding

2

mvStyleVar_FrameRounding

1

mvStyleVar_FrameBorderSize

1

mvStyleVar_ItemSpacing

2

mvStyleVar_ItemInnerSpacing

2

mvStyleVar_IndentSpacing

1

mvStyleVar_CellPadding

2

mvStyleVar_ScrollbarSize

1

mvStyleVar_ScrollbarRounding

1

mvStyleVar_GrabMinSize

1

mvStyleVar_GrabRounding

1

mvStyleVar_TabRounding

1

mvStyleVar_ButtonTextAlign

2

mvStyleVar_SelectableTextAlign

2

打印样式

常量

组件

mvPlotStyleVar_LineWeight

1

mvPlotStyleVar_Marker

1

mvPlotStyleVar_MarkerSize

1

mvPlotStyleVar_MarkerWeight

1

mvPlotStyleVar_FillAlpha

1

mvPlotStyleVar_ErrorBarSize

1

mvPlotStyleVar_ErrorBarWeight

1

mvPlotStyleVar_DigitalBitHeight

1

mvPlotStyleVar_DigitalBitGap

1

mvPlotStyleVar_PlotBorderSize

1

mvPlotStyleVar_MinorAlpha

1

mvPlotStyleVar_MajorTickLen

2

mvPlotStyleVar_MinorTickLen

2

mvPlotStyleVar_MajorTickSize

2

mvPlotStyleVar_MinorTickSize

2

mvPlotStyleVar_MajorGridSize

2

mvPlotStyleVar_MinorGridSize

2

mvPlotStyleVar_PlotPadding

2

mvPlotStyleVar_LabelPadding

2

mvPlotStyleVar_LegendPadding

2

mvPlotStyleVar_LegendInnerPadding

2

mvPlotStyleVar_LegendSpacing

2

mvPlotStyleVar_MousePosPadding

2

mvPlotStyleVar_AnnotationPadding

2

mvPlotStyleVar_FitPadding

2

mvPlotStyleVar_PlotDefaultSize

2

mvPlotStyleVar_PlotMinSize

2

节点样式

常量

组件

mvNodeStyleVar_GridSpacing

1

mvNodeStyleVar_NodeCornerRounding

1

mvNodeStyleVar_NodePaddingHorizontal

1

mvNodeStyleVar_NodePaddingVertical

1

mvNodeStyleVar_NodeBorderThickness

1

mvNodeStyleVar_LinkThickness

1

mvNodeStyleVar_LinkLineSegmentsPerLength

1

mvNodeStyleVar_LinkHoverDistance

1

mvNodeStyleVar_PinCircleRadius

1

mvNodeStyleVar_PinQuadSideLength

1

mvNodeStyleVar_PinTriangleSideLength

1

mvNodeStyleVar_PinLineThickness

1

mvNodeStyleVar_PinHoverRadius

1

mvNodeStyleVar_PinOffset

1