需要帮助从按下的按钮收集数据。[Python]

需要帮助从按下的按钮收集数据。[Python],python,tkinter,tkinter-button,Python,Tkinter,Tkinter Button,我正在尝试创建一个轮盘赌表(作为GUI完成)。现在,当我按下结果按钮时,它会在我的顶部框中显示数字,但我正在努力找到一种方法来收集列表中的结果,以便以后可以从列表中提取数据 例如,我想要一个过去结果的列表,这样我就可以显示它已经旋转了4圈而没有落在奇数上,或者它已经旋转了3圈,因为它是红色的,或者它平均每旋转3圈就落在前12圈 我尝试了很多方法从点击的按钮中收集结果,但没有任何效果 from tkinter import* # Roulette GUI root = Tk() root.

我正在尝试创建一个轮盘赌表(作为GUI完成)。现在,当我按下结果按钮时,它会在我的顶部框中显示数字,但我正在努力找到一种方法来收集列表中的结果,以便以后可以从列表中提取数据

例如,我想要一个过去结果的列表,这样我就可以显示它已经旋转了4圈而没有落在奇数上,或者它已经旋转了3圈,因为它是红色的,或者它平均每旋转3圈就落在前12圈

我尝试了很多方法从点击的按钮中收集结果,但没有任何效果

from tkinter import*


# Roulette GUI


root = Tk()
root.title("Roulette")


e = Entry(root, width=200, borderwidth=5)
e.grid(row=0, column=0, columnspan=13, padx=10, pady=10)


def button_click(number):
    e.delete(0, END)
    e.insert(0, number)
    print(number)

   

# define buttons


button_0 = Button(root, text="0", padx=40, pady=84, bg='green', command=lambda: button_click(0))
button_1 = Button(root, text="1", padx=40, pady=20, bg='red', command=lambda: button_click(1))
button_2 = Button(root, text="2", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(2))
button_3 = Button(root, text="3", padx=40, pady=20, bg='red', command=lambda: button_click(3))
button_4 = Button(root, text="4", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(4))
button_5 = Button(root, text="5", padx=40, pady=20, bg='red', command=lambda: button_click(5))
button_6 = Button(root, text="6", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(6))
button_7 = Button(root, text="7", padx=40, pady=20, bg='red', command=lambda: button_click(7))
button_8 = Button(root, text="8", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(8))
button_9 = Button(root, text="9", padx=40, pady=20, bg='red', command=lambda: button_click(9))
button_10 = Button(root, text="10", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(10))
button_11 = Button(root, text="11", padx=40, pady=20, bg='red', command=lambda: button_click(11))
button_12 = Button(root, text="12", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(12))
button_13 = Button(root, text="13", padx=40, pady=20, bg='red', command=lambda: button_click(13))
button_14 = Button(root, text="14", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(14))
button_15 = Button(root, text="15", padx=40, pady=20, bg='red', command=lambda: button_click(15))
button_16 = Button(root, text="16", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(16))
button_17 = Button(root, text="17", padx=40, pady=20, bg='red', command=lambda: button_click(17))
button_18 = Button(root, text="18", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(18))
button_19 = Button(root, text="19", padx=40, pady=20, bg='red', command=lambda: button_click(19))
button_20 = Button(root, text="20", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(20))
button_21 = Button(root, text="21", padx=40, pady=20, bg='red', command=lambda: button_click(21))
button_22 = Button(root, text="22", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(22))
button_23 = Button(root, text="23", padx=40, pady=20, bg='red', command=lambda: button_click(23))
button_24 = Button(root, text="24", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(24))
button_25 = Button(root, text="25", padx=40, pady=20, bg='red', command=lambda: button_click(25))
button_26 = Button(root, text="26", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(26))
button_27 = Button(root, text="27", padx=40, pady=20, bg='red', command=lambda: button_click(27))
button_28 = Button(root, text="28", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(28))
button_29 = Button(root, text="29", padx=40, pady=20, bg='red', command=lambda: button_click(29))
button_30 = Button(root, text="30", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(30))
button_31 = Button(root, text="31", padx=40, pady=20, bg='red', command=lambda: button_click(31))
button_32 = Button(root, text="32", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(32))
button_33 = Button(root, text="33", padx=40, pady=20, bg='red', command=lambda: button_click(33))
button_34 = Button(root, text="34", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(34))
button_35 = Button(root, text="35", padx=40, pady=20, bg='red', command=lambda: button_click(35))
button_36 = Button(root, text="36", padx=40, pady=20, bg='black', fg='white', command=lambda: button_click(36))
button_exit = Button(root, text="Exit", padx=60, pady=20, command=root.quit)

# put buttons on the screen

button_0.grid(row=1, rowspan=3, column=0)
button_1.grid(row=3, column=1)
button_2.grid(row=2, column=1)
button_3.grid(row=1, column=1)
button_4.grid(row=3, column=2)
button_5.grid(row=2, column=2)
button_6.grid(row=1, column=2)
button_7.grid(row=3, column=3)
button_8.grid(row=2, column=3)
button_9.grid(row=1, column=3)
button_10.grid(row=3, column=4)
button_11.grid(row=2, column=4)
button_12.grid(row=1, column=4)
button_13.grid(row=3, column=5)
button_14.grid(row=2, column=5)
button_15.grid(row=1, column=5)
button_16.grid(row=3, column=6)
button_17.grid(row=2, column=6)
button_18.grid(row=1, column=6)
button_19.grid(row=3, column=7)
button_20.grid(row=2, column=7)
button_21.grid(row=1, column=7)
button_22.grid(row=3, column=8)
button_23.grid(row=2, column=8)
button_24.grid(row=1, column=8)
button_25.grid(row=3, column=9)
button_26.grid(row=2, column=9)
button_27.grid(row=1, column=9)
button_28.grid(row=3, column=10)
button_29.grid(row=2, column=10)
button_30.grid(row=1, column=10)
button_31.grid(row=3, column=11)
button_32.grid(row=2, column=11)
button_33.grid(row=1, column=11)
button_34.grid(row=3, column=12)
button_35.grid(row=2, column=12)
button_36.grid(row=1, column=12)
button_exit.grid(row=4, column=11, columnspan=2)


root.mainloop()

如果您试图查看按下红色和黑色按钮的百分比,此代码将在控制台上打印

from tkinter import*
root = Tk()
root.title("Roulette")
e = Entry(root, width=200, borderwidth=5)
e.grid(row=0, column=0, columnspan=13, padx=10, pady=10)
results = []
def button_click(number):
    e.delete(0, END)
    e.insert(0, number)
    results.append(number)
    #loop through results
    count = 0
    for i in range(len(results)):
        if results[i]%2 == 0:
            count += 1
    print("Number is",number)
    red_percentage = count/len(results)*100
    print("Black", 100-red_percentage)
    print("Red", red_percentage)
    print("------------------------------------")
    
# define buttons
button = Button(root, text="0", padx=40, pady=84, bg='green', command=lambda: button_click(0))
button.grid(row=1, rowspan=3, column=0)
for i in range(0,36):
    if i%2 == 0:
        button = Button(root, text=str(i+1), padx=40, pady=20, bg='black', fg='white', command=lambda i=i:button_click(i+1))
    else:
        button = Button(root, text=str(i+1), padx=40, pady=20, bg='red', command=lambda i=i: button_click(i+1))
    button.grid(row=3 - i%3, column=int(i/3) + 1)

button = Button(root, text="Exit", padx=60, pady=20, command=root.quit)
button.grid(row=4, column=11, columnspan=2)
root.mainloop()

不知道你的问题是什么,除了说你已经尝试了很多东西之外,知道你尝试了什么也是很有用的。你能不能再多加几行描述你尝试过但没有成功的代码?我不理解你的问题。你不能在函数
按钮单击()
?@roganjosh中使用
我的列表。追加(数字)
“但我正在努力找到一种方法来收集列表中的结果,这样我以后可以从列表中提取数据”@furas当我按下任何按钮时,我希望它将该数字添加到我的列表中,所以,如果我按下红色1,我希望它将1添加到我的列表中。。。。我已经尝试过我的列表。append(number)但我无法让它工作,我是一个编码新手谢谢,我更喜欢序列,所以有多少次它是或不是一个特定的颜色或区域这里唯一缺少的是一点解释。也可以记录每一轮按下的计数按钮。