hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.69k stars 669 forks source link

dpg.create_viewport(title='中文', width=800, height=600) 并没有受到dpg.bind_font(font) 的影响 仍然是中文乱码 是否有解决办法 #2237

Closed fengmumu123123 closed 7 months ago

fengmumu123123 commented 7 months ago

相关测试代码如下

导入dearpygui库

import dearpygui.dearpygui as dpg

创建dearpygui上下文

dpg.create_context()

加载中文字体

with dpg.font_registry():

加载中文字体

with dpg.font("NotoSansSC-Regular.otf", 13) as font:
    # 添加中文字符范围
    dpg.add_font_range_hint(dpg.mvFontRangeHint_Default )
    # 添加字符范围提示,支持不同语言的字符
    # 可选项:
    #   mvFontRangeHint_Japanese (日语)
    #   mvFontRangeHint_Korean (韩语)
    #   mvFontRangeHint_Chinese_Full (完整中文)
    #   mvFontRangeHint_Chinese_Simplified_Common (简体中文常用)
    #   mvFontRangeHint_Cyrillic (西里尔文字)
    #   mvFontRangeHint_Thai (泰语)
    #   mvFontRangeHint_Vietnamese (越南语)
    dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
    dpg.add_font_range(0x4E00, 0x9FFF)
# 绑定字体
dpg.bind_font(font)

print("加载字体完成")

当用户尝试连接节点属性时运行的回调函数

def link_callback(sender, app_data):

app_data -> (link_id1, link_id2)

# 在节点编辑器中添加一个节点链接
dpg.add_node_link(app_data[0], app_data[1], parent=sender)

当用户尝试断开节点属性连接时运行的回调函数

def delink_callback(sender, app_data):

app_data -> link_id

# 删除指定的节点链接
dpg.delete_item(app_data)

创建一个窗口,标题为“Tutorial”,大小为400x400像素

with dpg.window(label="教程", width=400, height=400):

创建一个节点编辑器,指定链接和断开链接的回调函数

print("创建节点编辑器")
with dpg.node_editor(callback=link_callback, delink_callback=delink_callback):
    # 创建一个标签为“Node 1”的节点
    print("创建节点")
    with dpg.node(label="节点 1"):
        # 创建一个节点属性,包含一个浮点数输入框
        with dpg.node_attribute(label="节点 A1"):
            dpg.add_input_float(label="F1", width=150)

        # 创建一个输出类型的节点属性,包含一个浮点数输入框
        with dpg.node_attribute(label="节点 A2", attribute_type=dpg.mvNode_Attr_Output):
            dpg.add_input_float(label="F2", width=150)

    # 创建另一个标签为“Node 2”的节点
    with dpg.node(label="节点 2"):
        # 创建一个节点属性,包含一个浮点数输入框
        with dpg.node_attribute(label="节点 A3"):
            dpg.add_input_float(label="F3", width=200)

        # 创建一个输出类型的节点属性,包含一个浮点数输入框
        with dpg.node_attribute(label="节点 A4", attribute_type=dpg.mvNode_Attr_Output):
            dpg.add_input_float(label="F4", width=200)

创建一个视口,标题为“测试窗口”,大小为800x600像素

dpg.show_font_manager()

dpg.create_viewport(title='测试窗口', width=800, height=600) print("创建视口")

设置dearpygui

dpg.setup_dearpygui() print("设置dearpygui")

显示视口

dpg.show_viewport() print("显示视口")

启动dearpygui

dpg.start_dearpygui() print("启动dearpygui")

销毁dearpygui上下文

dpg.destroy_context() print("销毁dearpygui上下文")

fengmumu123123 commented 7 months ago

并且中文字符乱码问题 在未知条件下还有会造成无法启动gui 报错内容 进程已结束,退出代码-1073741819 (0xC0000005)

v-ein commented 7 months ago

I bet there are many people who would be upset by this ticket or at least by their own inability to read Chinese. Or maybe it's just me.

hugle commented 7 months ago

Is this closed because of the Chinese language or the problem was solved for real?

bandit-masked commented 7 months ago

Because of the Chinese language. If you can translate and it's a real issue, I could reopen the issue.

hugle commented 7 months ago

I don't think it is necessary. The issue is about displaying Chinese characters. I don't have an issue with that, so if @fengmumu123123 could provide the full functioning code to replicate the issue, I could help resolve it. It also seems duplicated with #1760

@fengmumu123123 你能提供完整可运行的测试代码吗? 是和这个相关吗 #1760 ?