I tried to make a data simulator in Python with Tkinter that shows the layout of the die in the window after rolling. For this, I defined a function that generates a random number from 1 to 6 and draws the data side on a screen depending on the number that came out and related that function to a button. The problem is that when I press the button, the function is not called or called but does not change the screen.
import tkinter as tk
import random as rd
def rolar_dado( canvas ):
rand = rd.randint(1, 6)
if rand == 1:
dot = canvas.create_oval(43, 43, 57, 57, fill='black')
elif rand == 2:
dot = canvas.create_oval(23, 23, 37, 37, fill='black')
dot2 = canvas.create_oval(63, 63, 77, 77, fill='black')
elif rand == 3:
dot = canvas.create_oval(23, 23, 37, 37, fill='black')
dot2 = canvas.create_oval(63, 63, 77, 77, fill='black')
dot3 = canvas.create_oval(43, 43, 57, 57, fill='black')
elif rand == 4:
dot = canvas.create_oval(23, 23, 37, 37, fill='black')
dot2 = canvas.create_oval(63, 63, 77, 77, fill='black')
dot3 = canvas.create_oval(23, 63, 37, 77, fill='black')
dot4 = canvas.create_oval(63, 23, 77, 37, fill='black')
elif rand == 5:
dot = canvas.create_oval(23, 23, 37, 37, fill='black')
dot2 = canvas.create_oval(63, 63, 77, 77, fill='black')
dot3 = canvas.create_oval(23, 63, 37, 77, fill='black')
dot4 = canvas.create_oval(63, 23, 77, 37, fill='black')
dot5 = canvas.create_oval(43, 43, 57, 57, fill='black')
elif rand == 6:
dot = canvas.create_oval(23, 23, 37, 37, fill='black')
dot2 = canvas.create_oval(63, 63, 77, 77, fill='black')
dot3 = canvas.create_oval(23, 63, 37, 77, fill='black')
dot4 = canvas.create_oval(63, 23, 77, 37, fill='black')
dot5 = canvas.create_oval(23, 43, 37, 57, fill='black')
dot6 = canvas.create_oval(63, 43, 77, 57, fill='black')
root = tk.Tk()
c = tk.Canvas(root, height = 100, width = 100)
square = c.create_rectangle(10, 10, 90, 90, fill='white')
c.pack()
b = tk.Button(root, text='Rolar', command = rolar_dado(c))
b2 = tk.Button(root, text='Sair', command=root.destroy)
b.pack(side=tk.LEFT)
b2.pack(side=tk.RIGHT)
root.mainloop()