文字列から該当する文字が何個あるかを検索したいのですが、値が渡せないためエラーになってしまいます。
EditBox_0.insert(tkinter.END,"abc")のように最初から入力すると、"abc"が含まれているのを数えるだけになります。
python
1import os, tkinter, tkinter.filedialog 2from tkinter import * 3 4def count(): 5 EditBox_0 = tkinter.Entry(width=30) 6 EditBox_0.place(x=5, y=40) 7 enter = EditBox_0.get() 8 output = str.count(enter) 9 print(output) 10 print("Process Completed!") 11 12def file_search(): 13 root = tkinter.Tk() 14 root.withdraw() 15 fTyp = [("","*.txt")] 16 iDir = os.path.abspath(os.path.dirname(__file__)) 17 file = tkinter.filedialog.askopenfilename(filetypes = fTyp,initialdir = iDir) 18 sub_win = Toplevel() 19 label_0 = tkinter.Label(sub_win,text=u'Search for letters.') 20 label_0.place(x=5, y=5) 21 button_0 = tkinter.Button(sub_win,text=u"Enter",width=25,command=count) 22 button_0.place(x=100, y=200) 23 sub_win.geometry("385x400") 24 with open(file, "r") as file: 25 str = file.read()
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\tkinter\__init__.py", line 1702, in __call__ return self.func(*args) File "C:\Users\onvcgkjcqh\Desktop\kaki\fir_win\txt_2.py", line 11, in count output = str.count(enter) TypeError: count() takes at least 1 argument (0 given)
もし解決方法をご存知の方がいらしゃれば、何卒ご教授よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。