Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在tkinter中使用画布绘制结果_Python_Graph_Tkinter - Fatal编程技术网

Python 在tkinter中使用画布绘制结果

Python 在tkinter中使用画布绘制结果,python,graph,tkinter,Python,Graph,Tkinter,我已经编写了我的代码,我想用图表显示每个骰子的掷骰次数。这不管用,我怎么做呢。我不想使用任何图形包 import random import time name="JORDAN SUMMERS RANDOM NUMBER GENERATOR ASSIGNMENT" by="## Created by Jordan Summers ##" date="@ 31.03.2015" symbol="_"*50 bos=""*5 warning = "Please enter a number, i.

我已经编写了我的代码,我想用图表显示每个骰子的掷骰次数。这不管用,我怎么做呢。我不想使用任何图形包

import random
import time

name="JORDAN SUMMERS RANDOM NUMBER GENERATOR ASSIGNMENT"
by="## Created by Jordan Summers ##"
date="@ 31.03.2015"
symbol="_"*50
bos=""*5
warning = "Please enter a number, i.e. 1. Not 'one'."
information=""" YOU WILL CHOOSE HOW MANY TIMES TO ROLL THE DICE,
ONCE ROLLED THE PROGRAM WILL PRINT THE NUMBERS, THEN IT WILL SORT THE NUMBERS
HIGHEST TO LOWEST. """
print("{:^80}\n{:^80}\n{:^80}\n{:^80}\n{:^80}\n{}".format(name,by,date,warning,symbol,bos,))


rolllist = []

total = 0



dice = int(input("How many times do you want to roll the dice? "))
if dice >50:
    print("Please enter a lower number") 
else:

    for i in range(dice):
        rolllist.append (random.randint(1,6))
        print ("You rolled a " + str(rolllist[i]))      #Here we are adding the results to the list

    total = sum(rolllist)
    print ("The total of the numbers " + str(total))    #This is calculating the total

    rolllist.sort()
    print ("numbers sorted " + str(rolllist))   #This is sorting the numbers in order of value

    a = rolllist.count(1)
    print ("The number 1 occured " + str(a) + " times." + " It's percentage is ") #Line 34 to line 51 are counting how many times a number occured.

    percent_1 = ((int(rolllist.count(1))/(dice)))
    print(percent_1*100)

    b = rolllist.count(2)
    print ("The number 2 occured " + str(b) + " times." + " It's percentage is ")

    percent_2 = ((int(rolllist.count(2))/(dice)))
    print(percent_2*100)

    c = rolllist.count(3)
    print ("The number 3 occured " + str(c) + " times." + " It's percentage is ")

    percent_3 = ((int(rolllist.count(3))/(dice)))
    print(percent_3*100)

    d = rolllist.count(4)
    print ("The number 4 occured " + str(d) + " times." + " It's percentage is ")

    percent_4 = ((int(rolllist.count(4))/(dice)))
    print(percent_4*100)

    e = rolllist.count(5)
    print ("The number 5 occured " + str(e) + " times." + " It's percentage is ")

    percent_5 = ((int(rolllist.count(5))/(dice)))
    print(percent_5*100)

    f = rolllist.count(6)
    print ("The number 6 occured " + str(f) + " times." + " It's percentage is")

    percent_6 = ((int(rolllist.count(6))/(dice)))
    print(percent_6*100)



    from tkinter import *

    root = Tk()

    canvas = Canvas(root, width = 640, height = 360, bg = "red")
    canvas.pack()

    canvas.create_rectangle(1, 360, 50,(a), fill = "black")
    canvas.create_rectangle(60,360, 100,(b), fill = "blue")
    canvas.create_rectangle(110,360, 150,(c), fill = "yellow")
    canvas.create_rectangle(160,360, 200,(d), fill = "white")
    canvas.create_rectangle(210,360, 250,(e), fill = "orange")
    canvas.create_rectangle(260,360, 300,(f), fill = "pink")
    root.mainloop()

我该怎么办。我想把它画出来,我现在做的应该行得通。我不明白。

注意:一定要写清楚问题所在。在这里,我浪费了一些时间去寻找它是什么。 所以你的第一个锐角有y坐标360和a。a总是很小的。 尝试以下方法:

    canvas = Canvas(root, width = 640, height = 100, bg = "red")    
    canvas.create_rectangle(1, 100, 50,100 - percent_1 *100, fill = "black")

另外,你的代码可能需要对循环进行一些重构。非常感谢你,顺便问一下,如果使用同一个系统,我需要改变什么坐标,只需移动新的矩形,这样你就可以看到这两个。我不理解你的评论。