以下を試してみてください。それは私はあなたがそれを必要だと思うものを行います「私はTkinterのファイル用のファイルタイプを探している」*
from tkinter import *
import json
class App:
def __init__(self, root):
self.root = root
self.keys = ["0", "1", "2"]
self.widget = [(Label(self.root), Entry(self.root)), (Label(self.root), Entry(self.root)), (Label(self.root), Entry(self.root))]
self.button = Button(self.root, text="Save", command=self.save)
for i in self.widget:
[1].pack()
for i in self.widget:
i[0].pack()
self.button.pack()
try:
with open("data.json", "r") as f:
self.data = json.load(f)
f.close()
for i in self.keys:
self.widget[int(i)][0].configure(text=self.data[i])
print(self.data)
except FileNotFoundError:
print("File not found")
except KeyError:
print("Keys do not match")
def save(self):
for (i, c) in self.widget:
i.configure(text=c.get())
with open("data.json", "w") as f:
json.dump({self.keys[0]: self.widget[0][1].get(), self.keys[1]: self.widget[1][1].get(), self.keys[2]: self.widget[2][1].get()}, f)
f.close()
root = Tk()
App(root)
root.mainloop()
* * Tkinterのファイル*としてはそのようなものはありません、TkinterにはPython用のライブラリです。したがって* tkinterファイル*は.pyまたは.pywファイル(またはパッケージ化された実行可能ファイル)です。あなたは実際に何を達成しようとしていますか、最終目標は何ですか? –
GUIは、ユーザーが入力した情報に従って別のフレームを作成します。この新しいGUIには、特定のWebページでブラウザを開くことができる特定のファイルやボタンから取得するボタンがあります。このプロセスは、ユーザーの入力が長かったので、私が望むものは、この新しいウィンドウ(GUI)を保存することです。そのため、ユーザーは同じGUIを繰り返し作成するプロセスを経る必要がありません。 – Mikaelo
ユーザーがプログラムを読み込むたびに、前回入力した情報がロードされるようにしますか? –