PILを使ってイメージを調べ、サイズ、色数、dpiなどを返すプログラムを作成しましたが、今は自分のコードをGUIに入れたいシステムを使用してユーザーを支援します。Python3とtkinter GUIボタンを使ってファイルを開く
私は関数内でaskopenfilename()
を使用しましたが、新しいファイルを開くときに問題が発生しています。私は、プログラムが起動した後に関数を実行し、ファイルを選択して正常に動作させることができます。ボタンをクリックして新しいファイルを開くと、新しいファイルを選択できますが、表示された情報は変更されません。
新しいファイルを選択した後、新しい情報で画面を更新するにはどうすればよいですか?
def openPattern():
global fileName
path = askopenfilename()
fileOpen = open(path, 'r')
fileName = os.path.basename(path)
if __name__ == '__main__':
root = Tk()
root.title("Art Intake | Developer Build")
ms = MainScreen(root)
ms.config(bg="grey")
openPattern()
pattern = Button(ms, text="Choose a file", command=openPattern,
highlightbackground='grey')
pattern.pack()
pName = Label(ms, text="Pattern Name: " + str(fileName),
bg='grey')
pName.pack()
read = Button(ms, text="ReadMe", command=openRM,
highlightbackground='grey')
read.place(rely=1.0, relx=1.0, x=-25, y=-15, anchor=SE)
quit = Button(ms, text="Quit", command=ms.quit,
highlightbackground='grey')
quit.place(rely=1.0, relx=1.0, x=-25, y=-45, anchor=SE)
root.mainloop()
ショーコード。コードなしでは広すぎる質問です。 BTW:多少のエラーメッセージが表示され、うまく動作しない可能性があります。コンソール/ターミナル/ cmd.exe/powershell – furas
show [minimal、but complete] )コード。あなたの答えを編集し、コメントにコードを投稿しないでください。 –
質問を編集してコードを追加してください。コメントはコードのための良い場所ではありません。 – furas