目次
品番検索プログラムを作る順序
1.品番検索プログラム①から⑪まで
2.品番を読み込みエクセルに品番ロケがあるかを調べるためのコード
3.tkinterに、リセットボタンと終了ボタンを作る
最後にtkinterに、リセットボタンと終了ボタンを作ります。
#ボックス内をクリアしてリセットして再度検索可能にする
def clear():
textbox1.delete(0,tk.END)
textbox2.delete(0,tk.END)
textbox3.delete(0,tk.END)
textbox4.delete(0,tk.END)
#リストクリア
hinban_list.clear()
roke_list.clear()
#カーソル位置をボックス内に戻す
textbox1.focus_set()
#終了
def end():
root.destroy()
#クリアボタン
button = tk.Button(text='クリア', font=("Meiryo", "12", "normal"), command = clear)
button.place(x=100, y =250, width=100, height=50 )
#閉じるボタン
button = tk.Button(text='終了', font=("Meiryo", "12", "normal"), command = end)
button.place(x=100, y =370, width=100, height=50 )
root.mainloop()
上から順番に見ていきます。
リセットの関数とボタンを作ることでプログラムを閉じることなく、
リセットして何度も検索可能にします。
def clear():
textbox1.delete(0,tk.END)
textbox2.delete(0,tk.END)
textbox3.delete(0,tk.END)
textbox4.delete(0,tk.END)
ボックス内をクリアするための
def clear():関数を作ります。
textbox1.delete(0,tk.END)
↑でボックス内をクリアします。
textbox1からtextbox4までをクリアします。
hinban_list.clear()
roke_list.clear()
hinban_list.clear()
roke_list.clear()
↑次に調べた品番ロケが存在した場合に
「品番」と「ロケ」を入れておいたリストの中身をクリアします。
#カーソル位置をボックス内に戻す
textbox1.focus_set()
リセットして再度検索可能になった時にカーソルも
すぐに入力できるようカーソル位置をボックス内に戻します。
def end():
root.destroy()
tkinterを終了する関数をつくり、
root.destroy()で終了させます。
#クリアボタン
button = tk.Button(text='クリア', font=("Meiryo", "12", "normal"), command = clear)
button.place(x=100, y =250, width=100, height=50 )
#閉じるボタン
button = tk.Button(text='終了', font=("Meiryo", "12", "normal"), command = end)
button.place(x=100, y =370, width=100, height=50 )
root.mainloop()
そして最後にボックス内をクリアするためのdef clear():関数と
tkinterを終了する関数を起動するためのボタン①②を作ります。
以上で完成です。


