私は初心者です。ユーザーの入力(エントリ)が(a)のランダムな単語と一致するかどうかを確認する基本的なプログラムを作成しようとしています。一致する場合は、新しい単語を入力し、入力フィールドをクリアする必要があります。ここでランダムな単語がユーザーの入力と同じかどうかを確認するにはどうすればよいですか?
私のコードは、これまでのところです:
import random
import requests
import Tkinter
import requests
from Tkinter import *
point = 0
word_site = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = requests.get(word_site)
WORDS = response.content.splitlines()
a = random.choice(WORDS)
root = Tkinter.Tk()
root.title("Stopwatch")
root.minsize(width=900, height=600)
root.configure(background='white')
e1 = Entry(root , justify='center')
e1.place(anchor=CENTER , bordermode=OUTSIDE)
e1.config(bg="white" , font="Geneva 30 bold")
e1.pack(expand=False, padx=20 , pady=20, ipadx=10, ipady=10)
label = Tkinter.Label(root, text = "Write this word: " + a , bg="white" , font="Geneva 30 bold")
label.pack()
if e1 == a: #virker ikke!
print "correct"
e1.delete(0, END)
root.mainloop()
どうすれば入力フィールドへの入力を文字列にすることができますか? –
@BenceSzabóこれは役に立ちます - https://stackoverflow.com/questions/15495559/taking-input-from-the-user-in-tkinter –
@BenceSzabóhttp://effbot.org/tkinterbook/entry.htmをチェックしてくださいさらに参照してください –