首页 > 解决方案 > 我想将 tkinter 添加到此代码中,并且会这样做,但我不知道将 tkinter 变量放在哪里?,它们最终会在 while true

问题描述

我的代码应该寻找搜索选项并附加到与搜索比较的列表中,我想弄清楚的是如何让 tkinter 进入循环,因为我不知道将诸如 if name == 之类的东西放在哪里主要”:东西

from tkinter import *
ideas = ["pooop", "pooop", "yaaah"]
describe = ["A software that provides poop images", "Fart noises", "kid on crack"]
window = Tk()
window.title("Exists?")






while True:

    function = input("Append or Search: ").lower().strip()

    if function == "append":
        appending = input("What would you like to append enter keywords/possible names..... ")
        ideas.append(appending)
        appending2 = input("Describe what you would like to append, please do not enter blank values as that will make "
                          "your software harder to find ")
        describe.append(appending2)
        print(ideas.index(str(appending)))
        print(describe.index(str(appending2)))
        searcher = input("What would you like to search for, enter keywords/possible names")
        if searcher in ideas:
            print(ideas)
            print("description: " + describe[ideas.index(searcher)])
            print(searcher in ideas)
            numberOfResults = str(ideas.count(searcher))
            print("0 results found")
        if searcher not in ideas:
            print(ideas)
            print(searcher in ideas)
            of = str(len(ideas))
            print("0 results found of " + of)

    if function == "search":
        searcher = input("What would you like to search for, enter keywords/possible names")
        if searcher in ideas:
            print(ideas)
            print("description: " + describe[ideas.index(searcher)])
            print(searcher in ideas)
            numberOfResults = str(ideas.count(searcher))
            print(numberOfResults + " results found")
        if searcher not in ideas:
            print(ideas)
            print(searcher in ideas)
            of = str(len(ideas))
            print("0 results found of " + of)

if __name__ == "__main__":
    window.mainloop()

标签: pythontkinter

解决方案


将代码置于无限循环中,当输入除appendor以外的单词时退出search

ideas = ["pooop", "pooop", "yaaah"]
describe = ["A software that provides poop images", "Fart noises", "kid on crack"]

while True:  # infinity loop
    function = input("Append or Search: ").lower().strip()

    if function == "append":
        pass  # ... you code instead

    elif function == "search":
        pass  # ... you code instead

    else:  # other input
        print("That's all!")
        break  # exit loop

推荐阅读