どのデータを呼び込むか或いはそのデータ内のどこを使用するかなどを、アプリを動作させる前に選択できるようにしようと思います。 例えば英単語の学習をするときに、レベルに合わせたデータを呼び込む時なのに便利だと思うのでtryしてみました。
やりたいことを纏めると次のようになります。
1 アプリをstartでformが立ち上がる
2 アプリのタイトル名、フォームの大きさを変更する
3 form上のtxtboxにそれらを記入す
4 その後でform上のrunをクリックでアプリがrunする
5 これでoriginalのtitle, sizeが変更されてアプリがstartする
要するに、アプリがstartする前にplayerの希望に従ってcodeの変数をsetしてからstartさせるのです。
# プログラム(code)をrunしたときに変更する–>フォームサイズや読込データなど 2/8/2021
import tkinter as tk
root = tk.Tk()
root.title(“Title”)
root.geometry(“200×200”)
# textの変更方法はwidgetにより異なる
# Labelの場合:label[“text”]=”New text
# Entryの場合:Entry.insert = textExample.get(1.0, tk.END)などなる
# run後にcode内のtitleとsizeを変更する 2/85/2021
lbl_1 = tk.Label(root, text=”enter new Title :”)
lbl_1.place(x=13, y=10)
txt_1 = tk.Entry(root)
txt_1.place(x=15, y=30)
lbl_2 = tk.Label(root, text=”enter new size :”)
lbl_2.place(x=13, y=60)
txt_2 = tk.Entry(root)
txt_2.place(x=15, y=80)
def change_title_size():
root.title(txt_1.get())
root.geometry(txt_2.get())
btnRead = tk.Button(root, height=1, width=20, text=”Any change?”,
command=change_title_size)
btnRead.place(x=20, y=150)
root.mainloop()
元図と変更図を載せます。
左が最初のcodeで描いた図、右が変更図
