【发布时间】:2020-12-03 16:38:01
【问题描述】:
代码
list = [ee1.get(), ee2.get(), ee3.get(), ee4.get(), ee5.get(), ee6.get(), ee7.get(), ee8.get(), ee9.get(), ee10.get()]
context = "What does", random.choice(list),"mean?"
labelquestion = Label(window, text = context, font = "Serif 10 bold")
问题
当我运行它时,它会输出"{What does} {} mean?"
如何解决这个问题,使其输出"What does"-random entry from list-"this mean?"
(列表中的东西都是条目)
【问题讨论】:
-
看起来这就是这段代码正在做的事情......你能发布一些minimal reproducible example吗?另外,尽量避免命名变量,如内置名称,如
list -
随机拉的ee好像是个空白对象。你确定 .get() 返回你想要的字符串吗?
-
这是因为
context是一个元组。请改用context = f'What does "{random.choice(list)}" mean?'。顺便说一句,不要使用关键字 (list) 作为变量名。 -
@acw1668 我已经按照你说的做了并且已经改进了,但是现在打印
"What does "" mean?"它不打印条目的输入。 -
请显示此代码的运行方式/时间。如果它没有显示数据,它可能在用户有机会输入任何内容之前运行。
标签: python tkinter python-3.7