前提・実現したいこと
Python初心者です。
PythonでAからZを自動的に打ってくれるソフトウェアを作っています。
実行をmain関数にした途端にエラーが起こりました。
process関数でAからZのキーを一定の間隔で押すつもりですが、まだそのプログラムは書いていません。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "F:/python projects/Type Engine/module1.py", line 56, in <module> main() File "F:/python projects/Type Engine/module1.py", line 43, in main startButton.bind("<Button-1>", process(waitTimeBox.get, spfBox.get)) File "F:/python projects/Type Engine/module1.py", line 51, in process sleep(waittime) TypeError: a float is required
該当のソースコード
Python
1import Tkinter as tk 2from time import sleep 3from pyautogui import press, hotkey 4 5processing = False 6# waittime = 0.5 7# spf = 0.1 8keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 9 'w', 'x', 'y', 'z'] 10 11 12def main(): 13 root = tk.Tk() 14 15 root.iconbitmap(default='icon.ico') 16 root.title(U"Type Engine") 17 root.geometry("355x300") 18 root.resizable(0, 0) 19 20 # diplay label 21 label1 = tk.Label(text=U"Type Engine-v1.0dev") 22 label1.place(x=0, y=282) 23 24 label2 = tk.Label(text=U"Wait Time before starting") 25 label2.place(x=0, y=5) 26 27 waitTimeBox = tk.Entry(justify="right", width=25) 28 waitTimeBox.place(x=160, y=5) 29 30 secLabel = tk.Label(text=U"sec") 31 secLabel.place(x=330, y=5) 32 33 label3 = tk.Label(text=U"Second per Frame") 34 label3.place(x=0, y=30) 35 36 spfBox = tk.Entry(justify="right", width=25) 37 spfBox.place(x=160, y=30) 38 39 seclabel2 = tk.Label(text=U"sec") 40 seclabel2.place(x=330, y=30) 41 42 startButton = tk.Button(text=U"Start", width=48) 43 startButton.bind("<Button-1>", process(waitTimeBox.get, spfBox.get)) 44 startButton.place(x=5, y=55) 45 46 47 root.mainloop() 48 49 50def process(waittime, spf): 51 sleep(waittime) 52 while processing: 53 sleep(spf) 54 55if __name__ == '__main__': 56 main() 57
試したこと
process関数の中をコメントアウトし代わりにPrintを実行して
Python
1import Tkinter as tk 2from time import sleep 3from pyautogui import press, hotkey 4 5processing = False 6# waittime = 0.5 7# spf = 0.1 8keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 9 'w', 'x', 'y', 'z'] 10 11 12def main(): 13 root = tk.Tk() 14 15 root.iconbitmap(default='icon.ico') 16 root.title(U"Type Engine") 17 root.geometry("355x300") 18 root.resizable(0, 0) 19 20 # diplay label 21 label1 = tk.Label(text=U"Type Engine-v1.0dev") 22 label1.place(x=0, y=282) 23 24 label2 = tk.Label(text=U"Wait Time before starting") 25 label2.place(x=0, y=5) 26 27 waitTimeBox = tk.Entry(justify="right", width=25) 28 waitTimeBox.place(x=160, y=5) 29 30 secLabel = tk.Label(text=U"sec") 31 secLabel.place(x=330, y=5) 32 33 label3 = tk.Label(text=U"Second per Frame") 34 label3.place(x=0, y=30) 35 36 spfBox = tk.Entry(justify="right", width=25) 37 spfBox.place(x=160, y=30) 38 39 seclabel2 = tk.Label(text=U"sec") 40 seclabel2.place(x=330, y=30) 41 42 startButton = tk.Button(text=U"Start", width=48) 43 startButton.bind("<Button-1>", process(waitTimeBox.get, spfBox.get)) 44 startButton.place(x=5, y=55) 45 46 47 root.mainloop() 48 49 50def process(waittime, spf): 51 print("Process") 52 #sleep(waittime) 53 #while processing: 54 #sleep(spf) 55 56if __name__ == '__main__': 57 main() 58
とするとエラーなく実行できました。
ただ、Processと表示されるのは実行した瞬間で、ボタンを押しても何も反応しませんでした。
インターネットで色々調べましたがすべて英語で、日本語に翻訳してもよくわかりませんでした。
補足情報(FW/ツールのバージョンなど)
実行:
Python 2.7.15
開発:
PyCharm
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/06 07:47