私はインタラクティブなPythonプログラミングに非常に慣れていないので、ご容赦ください。Python 3.3 で PyCharm を使用しています。
私は以下を構築しようとしています:
2 つのテキスト入力フィールドと 2 つのボタンを備えたインタラクティブ ウィンドウを表示する関数を生成したいと考えています。
-最初のボタン (START) は、小さなテキスト検索機能 (既に作成してテスト済み) を実行し、2 番目のボタン (QUIT) はアプリを終了します。
-最初のテキスト入力フィールドは検索対象の文字列 (例: "Hello Stack World") を受け取り、もう 1 つのテキスト入力フィールドは最初の入力文字列内で検索する文字列 (例: "Stack") を受け取ります。
計画では、2 つのテキスト フィールドが入力されたら、'START' ボタンを押すとテキスト検索機能が開始され、'QUIT' ボタンはプログラムを停止します。
問題は、'QUIT' ボタンは正常に機能しますが、'START' ボタンは何もしません。実際に私のプログラムを無限ループに送ると思います。
どんな助けでも本当に感謝しています。私はインターフェース/ウィジェットプログラミングの初心者です。
前もって感謝します!
これが私のコードです。
import tkinter
from tkinter import *
class Application(Frame):
def text_scan(self):
dataf = str(input()) '''string to be searched'''
s = str(input()) ''' string to search for'''
''' ... I will leave out the rest of this function code for brevity'''
def createWidgets(self):
root.title("text scan")
Label (text="Please enter your text:").pack(side=TOP,padx=10,pady=10)
dataf = Entry(root, width=10).pack(side=TOP,padx=10,pady=10)
Label (text="Please enter the text to find:").pack(side=TOP,padx=10,pady=10)
s = Entry(root, width=10).pack(side=TOP,padx=10,pady=10)
self.button = Button(root,text="START",command=self.text_scan)
self.button.pack()
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.filename = None
self.pack()
self.createWidgets()
root = Tk()
root.title("text scan")
root.quit()
app = Application(master=root)
app.mainloop()