DearPyGui
DearPyGui copied to clipboard
dpg.create_viewport(title='xxx'),Chinese coding problem
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.create_viewport(title='我是中文', width=600, height=200)
dpg.setup_dearpygui()
with dpg.font_registry():
with dpg.font(r"D:\0SDXX\DearPyGui\MiSans-Medium.ttf", 20) as default_font:
dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Full)
dpg.bind_font(default_font) # Binds the font globally
with dpg.window(label="我是中国文字"):
dpg.add_text("你好, 世界")
dpg.show_viewport()
# below replaces, start_dearpygui()
while dpg.is_dearpygui_running():
# insert here any code you would like to run in the render loop
# you can manually stop by using stop_dearpygui()
print("this will run every frame")
dpg.render_dearpygui_frame()
dpg.destroy_context()

The author probably does not convert unicode python str to wide char in the underlying windowing managment
If you realy need that, you may try to modify the source (for Windows) as shown below. It is a dirty solution without knowledge of all consequences but it is working for me. Maybe the correct fix should modify also the CreateWindow()
call in the mvShowViewport()
. I do not know.
src\platform\Windows\mvViewport.cpp:
#include <locale>
#include <codecvt>
#include "mvWindowsSpecifics.h"
...
std::wstring convert_to_wstring(const std::string& str)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
return conv.from_bytes(str);
}
...
mv_internal void
mvPrerender(mvViewport& viewport)
{
...
if (viewport.titleDirty)
{
SetWindowTextW(viewportData->handle, convert_to_wstring(viewport.title).c_str());
viewport.titleDirty = false;
}
...
}
Possible duplicate of #1667.
Workaround provided and possibly a duplicate. Closing the issue.
Hi, Why is this not included in the release? For me this is also a problem. And I have seen the same issues arise for other languages. Solution not actual for current 1.9.1/1.9.2 version