当我运行程序时,文本打印两次,我如何解决这个问题?选项根据问题列表中的数字显示。文本显示两次。
from tkinter import *
import random
tk = Tk()
canvas = Canvas(tk, width=750, height=750)
canvas.pack()
def startEasy():
questions = [1, 2]
random.shuffle(questions)
for x in range(len(questions)):
if questions[x] == 1:
txt = "How many legs does an octopus have?"
options=['a. 7', 'b. 4', 'c. 8']
execute(txt, options)
elif questions[x] == 2:
txt = "How many legs does an octopus have z?"
options=['a. 8', 'b. 5', 'c. 8']
execute(txt, options)
def execute(text1, options):
canvas.create_text(375, 200, text=text1, font=('Courier', 14))
aBtn = Button(tk, text=options[0],font=("Courier", 30), width=15, height=1, bg='white')
bBtn = Button(tk, text=options[1],font=("Courier", 30), width=15, height=1, bg='white')
cBtn = Button(tk, text=options[2],font=("Courier", 30), width=15, height=1, bg='white')
aBtn.place(x=187.5, y=225)
bBtn.place(x=187.5, y=300)
cBtn.place(x=187.5, y=375)
startEasy()
1条答案
按热度按时间9jyewag01#
如果不起作用,试试这个。
注解掉
startEasy()
函数中的text1 = text1 = text2[x]
。将text1
替换为txt = text2[x]