Python初心者です。
PythonのTk.Entryを使って、文字および数値をテキストファイルからロードし、Entryにinsertしてから編集し、最終的に名前を付けて改めて保存したいと考えています。
Entryに手打ちで入れた文字および数値を名前を付けて保存することはできたのですが、一旦保存したデータから再度元のEntryに値をinsertで戻すことができません。
どうやらEntryを指定する文字列がStrであり、<class 'tkinter.Entry'>ではないため、
AttributeError: 'str' object has no attribute 'insert'
というエラーが出ているようです。
classについてよく理解できていないため、どのようにしてEntryを指定する文字列のClassを 'tkinter.Entry'に変更したらよいのか分かりません。どなたかご意見を頂けると非常に有難いです。どうぞよろしくお願い申し上げます。
保存ファイルは以下のようなものです。
{'aaa': {'deck': 'deck1', 'position': 'A1', 'vial_volume': '111'},'bbb': {'deck': 'deck1', 'position': 'A2', 'vial_volume': '2222'}}
保存したデータを読み込む部分のコードです。
def click_load_button():
fTyp = [("","*")]
iDir = os.path.abspath(os.path.dirname(file))
filepath = filedialog.askopenfilename(filetypes = fTyp, initialdir = iDir)
file_path.set(filepath)
if filepath[-4:] == '.txt':
f = open(filepath, encoding="utf-8")
text_data = f.read()
textBox.insert(END, text_data)
dict=literal_eval(text_data)
key_names=dict.keys()
for name in key_names: str_position = dict[name]['position'] str_deck = dict[name]['deck'] str_volume= dict[name]['vial_volume'] Entry_name=str_deck+'_'+str_position+'_name' Entry_name_volume=str_deck+'_'+str_position+'_volume' print (Entry_name) #deck1_A1_nameとでてきます。 Entry_name.insert(tk.END, name) #NG AttributeError: 'str' object has no attribute 'insert'
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/08 09:08
2022/04/08 14:39