python - 我想将 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()
解决方案
将代码置于无限循环中,当输入除append
or以外的单词时退出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
推荐阅读
- python - while 循环和计数器
- flutter - 我想使用颤振导航我在网格视图中的卡片。我的卡片包含图像而不是图标
- python - Google Drive API 使用 Python 下载文件
- python - 如何在 Flask 中获取请求的参数?
- python-3.x - Tensorflow2 数据流水线如何优化?
- ruby - 在 macOS 上更新 RVM、Ruby 和 Rails
- docker - 无法使用 docker ps -a 列出已停止的容器
- java - 更新区域设置不会更改低于 Build.VERSION_CODES.N (API 24) 的 Android 版本的区域设置
- android - java.lang.SecurityException:权限拒绝:启动意图
- c# - 带有附件的 Azure 函数 POST 请求