输入一个字符串(例如“您叫什么名字?”)。输入中始终包含我要提取的问题。但是我要解决的问题是输入总是带有不需要的输入。
因此,输入可以是(但不限于)以下内容:
1- "eo000 ATATAT EG\n\nWhat is your name?\nkgda dasflkjasn"
2- "What is your\nlastname and email?\ndasf?lkjas"
3- "askjdmk.\nGiven your skills\nhow would you rate yourself?\nand your name? dasf?"
(请注意,在第三个输入处,问题以单词“ Given”开头,以“您自己?”结尾)
上面的输入示例是由pytesseract OCR库生成的,该库扫描图像并将其转换为文本
我只是想提取垃圾输入,并没有别的问题。
我尝试使用re库的find('?',1)函数来获取问题的最后一部分的索引(现在假设第一个问号始终是问题的结尾,而不是我输入的一部分)不想)。但是我不知道如何获得问题首字母的索引。我试图反向循环并在输入中得到第一个点\ n,但是问题并不总是在问题的第一个字母前有\ n。
def extractQuestion(input):
index_end_q = input.find('?', 1)
index_first_letter_of_q = 0 # TODO
question = '\n ' . join(input[index_first_letter_of_q :index_end_q ])
Run Code Online (Sandbox Code Playgroud) 用户单击按钮后,我想创建一个包含建议的新顶级窗口,当用户在顶级窗口上选择他/她的建议并单击“完成”按钮时,我想销毁顶级窗口并将所选结果传递给根窗口。这就是我想要实现的目标,但到目前为止我还无法正确地做到这一点。
我尝试wait_window在顶层窗口上使用,但这并不是每次都有效,因为有时它不会返回任何内容或无限期冻结。
import tkinter as tk
root = None
BTN = None
listbox = None
selected = None
SUGGESTIONS = [(0, "level 1"), (11, "level 2"), (23, "level 3")]
def select():
global listbox, SUGGESTIONS, selected
selected = listbox.get(tk.ANCHOR)
for (idd, info) in SUGGESTIONS:
if selected == f_info:
selected = idd
def show_suggestions():
global SUGGESTIONS, listbox
win = tk.TopLevel()
win.title("Select suggestion")
win.geometry("400x400")
listbox = tk.Listbox(win, height=20, width=40)
listbox.pack(pady=15)
self.btn = tk.Button(win, text="Confirm selection", command=select)
self.btn.pack(pady=10)
for (idd, info) in …Run Code Online (Sandbox Code Playgroud)