我工作的一个项目,在这个项目中,如果能够确定一个特定的字母应该使用Tkinter的选项进行更改,如果它在一个文本文件中存在的读取。这是我迄今所做的。
import cv2
import numpy as np
from tkinter import *
import tkinter as tk
combine = [('THO#N', [(7, 5), (7, 6), (7, 7), (7, 8), (7, 9)])]
for word, cord in combine:
for letter in word:
if letter == '#':
def read_save():
blank_tile = entry_1.get()
blank_letter = blank_tile
text_file = open("blanktile.txt", "w")
text_file.write(blank_letter)
text_file.close()
f = open('blanktile.txt','r')
input_tile = f.read()
word = [letter.replace('#', input_tile)]
root.destroy()
root = tk.Tk()
label_1 = tk.Label(root,text = "Please input a letter for the blank tile")
label_1.pack()
entry_1 = tk.Entry(root)
entry_1.pack(fill=X)
save_button = tk.Button(root, text="Save", command=read_save)
save_button.pack(fill=X)
root.mainloop()
if word in open('sowpods.txt').read():
print(word + ' ' + "Exist in the dictionary")
else:
print(word + ' ' + "Does not exist in the dictionary")
我想这个代码,但它似乎没有改变,它直接进入在字典中不存在。如何更换#到特定的字母,并检查是否在词上的文本文件?这是我的文本文件看起来像。输出应该是,如果我把R上的Tkinter窗口,然后点击保存它看起来像荆棘和检查,如果不是它应该被删除存在这个词。谢谢。 Click here to get text file
我想要的输出是,如果它确定在THO#N字例子的#。它会显示弹出并且用户必须输入一个字母例如“R”,然后按然后保存“R”将取代“#”。这使得结合= [( 'THORN',[(7,5),(7,6),(7,7),(7,8),(7,9)])]。如果它存在,如果没有弹出将表明,它不存在,并在列表中的值删除这个词也检查文本字眼中钉。
有人能帮助吗?
根据我的理解:脚本能让字母,然后在Word #
取代THO#N
,然后在词典搜索词:
import tkinter as tk
WORD = 'THO#N'
def find_word():
word = WORD.replace('#', entry.get().upper())
if word in words:
label.setvar('Word "{}" exist in the dictionary'.format(word))
label.config(text='Word "{}" exist in the dictionary'.format(word))
else:
label.config(text='Word "{}" not exist in the dictionary'.format(word))
words = [line.rstrip('\n') for line in open('sowpods.txt')]
root = tk.Tk()
label = tk.Label(root, text='Please input a letter for the blank tile')
label.pack()
entry = tk.Entry(root)
entry.pack(fill=tk.X)
save_button = tk.Button(root, text='Save', command=find_word)
save_button.pack(fill=tk.X)
root.mainloop()
例如:
R
和接收结果:Word THORN exist in the dictionary
A
和接收结果:Word THOAN not exist in the dictionary