尝试用迭代循环来制作多个饼图,只不过是开始了

2024-04-20 13:16:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用以下代码制作多个饼图:

n = 0
perc = list()
while n < len(piedata):
    perc.append(piedata[n+2])
    n += 3
print (perc)
n = 0
fails = list()
while n < len(piedata):
    fails.append(piedata[n+1])
    n += 3
print(fails)

n = 0
titles = list()
while n < len(piedata):
    titles.append(piedata[n])
    n += 3
print(titles)
for percent, fail, title in zip(perc, fails, titles):
    piedata = [percent, (100-int(percent))]

    fig = matplotlib.figure.Figure(figsize=(5, 5))
    ax = fig.add_subplot(111)
    ax.pie(piedata)  # this is the information that the circle diagram will be made out of
    ax.legend([('amount of attempts:', NOTT), ('amount of fails', fail)])

    circle = matplotlib.patches.Circle((0, 0), 0.7, color='white')
    ax.add_artist(circle)


    # this is the code for actually putting the circle diagram/pie chart on the screen
    canvas = FigureCanvasTkAgg(fig, master=window)
    canvas.get_tk_widget().pack()
    canvas.draw()

    Label(window, text=(title, title), bg='light blue').pack()

    window.mainloop()
    print(percent)
    print(fail)

据我所知,我的问题是window.mainloop()最后只能使用一次,然后就不能再使用了。你知道吗

我正在试图得到它目前2个循环。你知道吗


Tags: thelenaxwindowlistfailprintpercent
1条回答
网友
1楼 · 发布于 2024-04-20 13:16:28

任何发现这个的人: tk.主回路()(就我而言窗口.mainloop())在许多情况下停止程序窗体的运行。这是一个非常简化的版本,但如果您遇到了这个问题,答案可能是将其替换为:

  window.update_idletasks()
            window.update()

但是,如果像我一样在循环中使用它,则需要添加break子句,或者使用for循环,否则它将继续循环。你知道吗

相关问题 更多 >