Python 如何更改列表中的字母,然后检查该单词在文本文件中是否有效?

Python 如何更改列表中的字母,然后检查该单词在文本文件中是否有效?,python,tkinter,text-files,Python,Tkinter,Text Files,我在一个项目中工作,在这个项目中,如果它标识了一个特定的字母,那么应该使用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:

我在一个项目中工作,在这个项目中,如果它标识了一个特定的字母,那么应该使用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")
我尝试了这段代码,但它似乎没有改变,它直接转到字典中不存在。如何将a替换为特定的字母,并检查该单词是否在文本文件中?我的文本文件如下所示。如果我在Tkinter窗口上放置R并单击save,则输出应该是,它将看起来像THORN,并检查此单词是否存在,如果不存在,则应将其删除。多谢各位

我想要的输出是,如果它在THON中的一个单词示例中标识a。它将显示一个弹出窗口,用户必须输入一个字母示例R,然后按saves,然后R将替换。这使得combine=['THORN',[7,5,7,6,7,7,7,8,7,9]]。还检查文本中的单词THORN(如果存在),如果不存在,则pop将显示该单词不存在,并删除该单词及其在列表中的值


有人能帮忙吗?

根据我的理解:脚本获取字母,然后替换为单词THON,然后在字典中搜索单词:

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并收到结果:单词THORN存在于字典中 您正在输入单词A并收到结果:字典中不存在单词THOAN

您可以将测试文件作为文本而不是屏幕截图发布吗?并显示预期结果好的,等等,但我的测试文件非常大,所以我要把它放在一个超链接文件中,这里的X是什么:fill=X?你能提供完整的代码,以便在我的电脑上调试吗?哦,x就像是一个调整在tkinter。如果我使用fill=X,按钮上的小部件将占据水平方向的所有空间,如果y是垂直方向的。你能提供完整的代码示例吗,我不想发明什么如果我单击save将组合=['THON',[7,5,7,6,7,7,7,8,7,9]]变成组合=['THORN',[7,5,7,6,7,7,8,9]]?这些字母是什么意思?这些字母只是坐标,我只是想知道它是否在一个单词中标识,弹出消息是否会显示,如果指定一个字母,单击“保存”,它将更改为特定的字母坐标是什么?我正在做的项目是检测拼字,所以我需要这些坐标来找到位置它们被放置。我的问题是,如果一个玩家放了一个空白的磁贴,它应该识别它,并使用弹出菜单将其替换为一个特定的字母。