Hello,I’m using DirectEntry in my code,but it does not work when input Chinese characters.
I need some help to fixed this.
Already set “text-use-harfbuzz true” in the Config.prc file which in the setup folder/ect.
Here is my code below.
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *
#add some text,want to display some Hanzi content
bk_text = “这是我的Demo” #displaying Hanzi, works
font = loader.loadFont(“zkwy.ttf”)#load target Hanzi font
textObject = OnscreenText(text=bk_text, pos=(0.95, -0.95), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)
textObject.setFont(font)#set target Hanzi font
#callback function to set text
def setText(textEntered):
print(“text entered”)
textObject.setText(textEntered)
#add text entry
entry = DirectEntry(text = “”, scale=.05, command=setText,
initialText=“输入Something”, numLines = 2, focus=1,
entryFont=font)#set entryFont to enable display Chinese Hanzi
#run the tutorial
base.run()
When runs the code, it can display the Chinese Character Hanzi content in both OnscreenText and DirectEntry, But just can’t input Chinese Hanzi content.
Here is the detailed program behavior when trying to input Hanzi.
The IME works when try to input Hanzi. After finish Hanzi content input, there appears a widget with a green arrow on it. It maybe some widget works together with IME, But the Chinese characters can’t put into the entry.
It seems that, the Panda3d widget can’t get content from IME, or can’t update its appearance after got Hanzi content.
The following is the developing environment Information.
Windows 11
Python 3.12.2
Panda3D-SDK-1.10.15-x64
IME Sogou, download link, https://shurufa.sogou.com/
Please help,thanks a lot.
This issue has been resolved. Thanks for rdb’s work. .If anyone encounters the same problem, please set the following settings so that DirectEntry can display Chinese characters normally
- In the etc folder of the Panda3D installation directory, find Config. prc and add the following two lines of configuration
text-use-harfbuzz true #
ime-aware true # - What needs to be done in programming
You need to first load the required Chinese font, for example: font=loader. loadFont (“zkwy. ttf”) # Load the Chinese font ttf file. This example code places the ttf file in the same path of the code.
When writing the program, you need to set entryFont to the Chinese font above for DirectEntry. The code is as follows:
entry = DirectEntry(text = “”, scale=.05, command=setText,
InitiatText=“Enter Something”, numLines=2, focus=1
entryFont=font) - By the way, if you need to use the OnscreenText class in the program to display Chinese characters, you need to set its font by setFont method. The example is as follows
textObject = OnscreenText(text=bk_text, pos=(0.95, -0.95), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)
textObject.setFont(font)# Set as the loaded Chinese character font
Finally, DirectEntry can happily input and display Chinese characters.
Have fun.