前提
pythonのtkinterを使ってタイピングソフトを制作しています。
左に表示されている問題文を右に打ち込んで一致しているかを判断します。
実現したいこと
問題文と一致している文字だけを■に置き換えて表示させたい。
発生している問題・エラーメッセージ
打ち込んだ文字が間違っていても置き換えられずそのまま表示され、すべて一致している時だけ置き換えられて■しか表示されない。
該当のソースコード
python
1import re 2import tkinter as tk 3baseGround = tk.Tk() 4 5baseGround.title('W3S4') 6baseGround.geometry('1400x850') 7baseGround.configure(bg="#baffb5") 8 9f = open('1.txt',encoding='UTF-8') 10txt1 = f.read() 11 12def judge(): 13 txt2 = textbox_input.get(1.0,tk.END) 14 end = re.sub(txt1, '■', txt2) 15 print(end) 16 17Button_judge = tk.Button(baseGround, text='判定',height=12,width=9,command=judge) 18textbox_input = tk.Text(width=50,height=70,font=("",18)) 19textbox = tk.Text(width=50,height=70,font=("",18)) 20textbox.insert(tk.END,txt1) 21 22textbox_input.place(x=745,y=30) 23textbox.place(x=45,y=30) 24Button_judge.place(x=660,y=350) 25 26baseGround.mainloop()
補足情報(FW/ツールのバージョンなど)
ソースコードのtxt1が問題文、txt2が打った文字です。
python3.10.4
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。