【PysimpleGUI】パスワードを自動作成するプログラムを組みたい

実現したいこと

プログラミング勉強中の者です。
pythonで文字数を入力するとランダムの文字でパスワードを自動作成するプログラムを作りたいのですが、以下のようなエラーが出て消えず困っています。
整数以外を入力するとエラーのポップアップが出るようにしたいです。
ご教授の程よろしくお願い致します。

発生している問題・エラーメッセージ

実行すると以下のポップアップが表示されます。

Error Unable to complete operation on element with key 0

You cannot perform operations (such as calling update) on an Element until:
window.read() is called on finalize=True when Window created.Addng a ‘’finalize = True” parameter to your Window creation will likely fix this.
The error originated from:
File C:\Users\xxxxxxx\anaconda3\lib\warning.py
Line 30
In_showwarnimsg_impl_
File.write(text)

該当のソースコード

import PySimpleGUI as sg
import secrets
import string

sg.theme('DarkAmber')

layout = [
[sg.Text('桁数設定', size=(5, 1)), sg.InputText('', size=(8, 1), key='page1'), sg.Text('※設定するパスワードの桁数を入力してください', size=(20, 3))],
[sg.Output(size=(70,3))]
]

window = sg.Window('パスワードを作成します', layout)

chars = string.ascii_letters + string.digits

input_num = input('')
if not input_num.isdigit():
sg.PopupGetText('エラーです', title='Error')

password = "".join([secrets.choice(chars) for i in range(int(input_num))])

while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break

#終了処理
window.close()

補足情報

windows10,開発環境はPyCharm Community Edition 2022.3.1

コメントを投稿

0 コメント