第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將鍵盤輸入變成unicode/日文字符?

如何將鍵盤輸入變成unicode/日文字符?

SMILET 2024-01-15 15:20:31
我有以下功能 def game_test_write_vocabularuy():        game_test = True            active = False        text_hiragana = ''            while game_test == True:                for event in pygame.event.get():                if event.type == pygame.QUIT:                    terminate()                if event.type == pygame.KEYDOWN:                    if active == True:                        if event.key == pygame.K_BACKSPACE:                            text_hiragana = text_hiragana[:-1]                        else:                            text_hiragana += event.unicode                if event.type == pygame.MOUSEBUTTONDOWN:                    if input_rectangle.collidepoint(event.pos):                        active = True                    else:                        active = False                    game_display.fill(white)                    if active:                pygame.draw.rect(game_display,gray,input_rectangle,2)            else:                pygame.draw.rect(game_display, red, input_rectangle, 2)            textFunc(FontJapoMedium,text_hiragana,black,input_rectangle[0] + 5,input_rectangle[1] + 5 ,False)                    Clock.tick(FPS)            pygame.display.update()基本上,它允許我輸入一些內(nèi)容,然后它就會呈現(xiàn)在屏幕上。問題是,當(dāng)我打開日語鍵盤并開始打字時,它不顯示日語文本。相反,它只是顯示羅馬字母例如,在我的鍵盤中 D = し,但是當(dāng)我按下 D 鍵時,沒有渲染し,而是沒有渲染任何內(nèi)容;好像該活動未注冊 我該怎么辦?注意-字體不是問題
查看完整描述

2 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊

我是這樣解決的:


我只是用字典將字符轉(zhuǎn)換為平假名


 Table = {

#A Column

'a':'あ',

'ka':'か',

'ga':'が',

'sa':'さ',

'za':'ざ',

'ta':'た',

'da':'だ',

'na':'な',

'ha':'は',

'ba':'ば',

'pa':'ぱ',

'ma':'ま',

'ya':'や',

'ra':'ら',

'wa':'わ',


#I Column

'i':'い',

'ki':'き',

'gi':'ぎ',

'shi':'し',

'ji':'じ',

'chi':'ち',

'ni':'に',

'hi':'ひ',

'bi':'び',

'pi':'ぴ',

'mi':'み',

'ri':'り',


#U Column

'u':'う',

'ku':'く',

'gu':'ぐ',

'su':'す',

'zu':'ず',

'tsu':'つ',

'nu':'ぬ',

'fu':'ふ',

'bu':'ぶ',

'pu':'ぷ',

'mu':'む',

'ru':'る',

'yu':'ゆ',


#E Column

'e':'え',

'ke':'け',

'ge':'げ',

'se':'せ',

'ze':'ぜ',

'te':'て',

'de':'で',

'ne':'ね',

'he':'へ',

'be':'べ',

'pe':'ぺ',

'me':'め',

're':'れ',


#O Column

'o':'お',

'ko':'こ',

'go':'ご',

'so':'そ',

'zo':'ぞ',

'to':'と',

'do':'ど',

'no':'の',

'ho':'ほ',

'bo':'ぼ',

'po':'ぽ',

'mo':'も',

'yo':'よ',

'ro':'ろ',

'wo':'を',


#N sound

'nn':'ん',


#Characters with 3 sounds that use the small Y characters

'kya':'きゃ',

'kyu':'きゅ',

'kyo':'きょ',


'sha':'しゃ',

'shu':'しゅ',

'sho':'しょ',


'cha':'ちゃ',

'chu':'ちゅ',

'cho':'ちょ',


'nya':'にゃ',

'nyu':'にゅ',

'nyo':'にょ',


'hya':'ひゃ',

'hyu':'ひゅ',

'hyo':'ひょ',


'mya':'みゃ',

'myu':'みゅ',

'myo':'みょ',


'rya':'りゃ',

'ryu':'りゅ',

'ryo':'りょ',


'gya':'ぎゃ',

'gyu':'ぎゅ',

'gyo':'ぎょ',


'ja':'じゃ',

'ju':'じゅ',

'jo':'じょ',


'bya':'びゃ',

'byu':'びゅ',

'byo':'びょ',


'pya':'ぴゃ',

'pyu':'ぴゅ',

'pyo':'ぴょ',


#Weird characters rarely used

'di':'ぢ',

'du':'づ',


#Small Tsu

'kk':'っ',

'ss':'っ',

'tt':'っ',

'hh':'っ',

'mm':'っ',

'yy':'っ',

'rr':'っ',

'ww':'っ',

'gg':'っ',

'zz':'っ',

'dd':'っ',

'bb':'っ',

'pp':'っ',


}

然后我使用了以下函數(shù)


   def deleteText(self):

    if len(self.text) > 0:

        self.textoChico = self.textoChico[:-1]

    else:

        self.texto = self.texto[:-1]


def writeText(self):

    if len(self.text) > 3:

        self.text = ""

    if self.text in Table :

        self.texto += Table [self.text]

        self.text = ''


查看完整回答
反對 回復(fù) 2024-01-15
?
幕布斯6054654

TA貢獻(xiàn)1876條經(jīng)驗 獲得超7個贊

我認(rèn)為這取決于你的輸入法。在 Linux PyGame 上使用“Anthy”IBus 輸入可以很好地輸入平假名文本。

懷疑您的鍵盤正在發(fā)送拉丁字符,并通過軟件驅(qū)動程序?qū)⑵滢D(zhuǎn)換為平假名(等),但 PyGame 正在較低級別處理鍵盤,因此接收原始按鍵而不是轉(zhuǎn)換。

參考代碼:

import pygame


# Window size

WINDOW_WIDTH? ? = 600

WINDOW_HEIGHT? ?= 100

WINDOW_SURFACE? = pygame.HWSURFACE|pygame.DOUBLEBUF|pygame.RESIZABLE


DARK_BLUE = (? ?3,? ?5,? 54 )

WHITE? ? ?= ( 255, 255, 250 )



### initialisation

pygame.init()

pygame.mixer.init()

window = pygame.display.set_mode( ( WINDOW_WIDTH, WINDOW_HEIGHT ), WINDOW_SURFACE )

pygame.display.set_caption("Hiragana Test")


### For the simple text handling

#font? ? ?= pygame.font.SysFont( None, 16 )

font? ? ?= pygame.font.Font( 'umeboshi.ttf', 16 )

text? ? ? = ''

text_surf = font.render( text, True, WHITE )


### Main Loop

clock = pygame.time.Clock()

done = False

while not done:


? ? # Handle user-input

? ? for event in pygame.event.get():

? ? ? ? if ( event.type == pygame.QUIT ):

? ? ? ? ? ? done = True

? ? ? ? elif ( event.type == pygame.MOUSEBUTTONUP ):

? ? ? ? ? ? # On mouse-click

? ? ? ? ? ? pass

? ? ? ? elif ( event.type == pygame.KEYDOWN ):

? ? ? ? ? ? if ( event.key == pygame.K_BACKSPACE ):

? ? ? ? ? ? ? ? text = text[:-1]

? ? ? ? ? ? else:

? ? ? ? ? ? ? ? text = text + event.unicode

? ? ? ? ? ? #print( "TEXT: [%s]" % ( text ) )

? ? ? ? ? ? text_surf = font.render( text, True, WHITE )


? ? # Update the window, but not more than 60fps

? ? window.fill( DARK_BLUE )

? ? window.blit( text_surf, ( 10, WINDOW_HEIGHT//2 ) )

? ? pygame.display.flip()


? ? # Clamp FPS

? ? clock.tick_busy_loop(60)



pygame.quit()


查看完整回答
反對 回復(fù) 2024-01-15
  • 2 回答
  • 0 關(guān)注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號