前提・実現したいこと
PYTHON初心者です。
PYTHON3でTKINTERを用いて、処理の前提となる入力用ダイアログボックスを作成しています。
発生している問題・エラーメッセージ
ダイアログボックスには、ボックス右上の×ボタン以外に"OK","Cancel"ボタンがありますが、
OKボタンをクリックしても、意図した動作にならない事象が発生しています。
※右上×ボタンと、"Cancel"ボタンは意図した通りに動く
具体的には、本プログラムを起動した段階で、
なぜかbutton1_clicked()の関数が実行されてしまい(コンソールに"テスト"と出力される)、
以降、"OK"ボタンをクリックしても何も反応が無い状態です。
本来は"OK"を押せば、単純にダイアログボックスを閉じて"以降の処理"を続行したいと思っています。
該当のソースコード
PYTHON
1from tkinter import * 2from tkinter import ttk 3from tkinter import messagebox 4 5# "OK"ボタンクリック時 6def button1_clicked(): 7 root.quit() 8 print("テスト") 9 10# 右上×ボタンクリック時 11def on_closing(): 12 if messagebox.askokcancel("Quit", "Do you want to quit?"): 13 sys.exit() 14 15if __name__ == '__main__': 16 root = Tk() 17 root.title("TEST INPUT") 18 root.resizable(False, False) 19 frame1 = ttk.Frame(root, padding=10) 20 frame1.grid() 21 22 label1 = ttk.Label(frame1, text="Login ID", padding=(5,2)) 23 label1.grid(row=0,column=0,sticky=E) 24 25 label2 = ttk.Label(frame1, text="Password", padding=(5,2)) 26 label2.grid(row=1,column=0,sticky=E) 27 28 # Login ID Entry 29 loginid = StringVar() 30 loginid_entry = ttk.Entry( 31 frame1, 32 textvariable=loginid, 33 width=30 ) 34 loginid_entry.grid(row=0,column=1) 35 36 # Password Entry 37 password = StringVar() 38 password_entry = ttk.Entry( 39 frame1, 40 textvariable=password, 41 width=30, 42 show="*" ) 43 password_entry.grid(row=1,column=1) 44 45 frame2 = ttk.Frame(frame1, padding=(0,5)) 46 frame2.grid(row=4,column=1,sticky=W) 47 48 button1 = ttk.Button(frame2, text="OK",command=button1_clicked()) 49 button1.pack(side=LEFT) 50 51 button2 = ttk.Button(frame2, text="Cancel",command=quit) 52 button2.pack(side=LEFT) 53 54 root.protocol("WM_DELETE_WINDOW", on_closing) 55 root.mainloop() 56 57 以降の処理 58 ・ 59 ・ 60 ・
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/24 04:31