In this case, the button presses create the number that is needed to be displayed in the GUI. I am trying to make a dice roller where everything is handled through a Tkinter GUI, and outside of the shell. As of right now the output of the button presses is displayed in the console rather than in the label created. I have an incomplete label included as a blank space to include the solution once I have it.
Thank you for your help in advance!
import tkinter as tk
root = tk.Tk()
root.title('Choose the dice to roll.')
frame = tk.Frame(root)
frame.pack()
def d20():
import random
for x in range(1):
print (random.randint(1,20))
def d12():
import random
for x in range(1):
print (random.randint(1,12))
def d8():
import random
for x in range(1):
print (random.randint(1,8))
def d6():
import random
for x in range(1):
print (random.randint(1,6))
def d4():
import random
for x in range(1):
print (random.randint(1,4))
d20_button = tk.Button(frame,
text="Click here to roll a D20",
command=d20)
d20_button.pack(side=tk.LEFT)
d20_button.config(height = 10, width = 20)
d12_button = tk.Button(frame,
text="Click here to roll a D12",
command=d12)
d12_button.pack(side=tk.LEFT)
d12_button.config(height = 10, width = 20)
d8_button = tk.Button(frame,
text="Click here to roll a D8",
command=d8)
d8_button.pack(side=tk.LEFT)
d8_button.config(height = 10, width = 20)
d6_button = tk.Button(frame,
text="Click here to roll a D6",
command=d6)
d6_button.pack(side=tk.LEFT)
d6_button.config(height = 10, width = 20)
d4_button = tk.Button(frame,
text="Click here to roll a D4",
command=d4)
d4_button.pack(side=tk.LEFT)
d4_button.config(height = 10, width = 20)
quit_button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
quit_button.pack(side=tk.LEFT)
quit_button.config(height =10, width = 5)
number_result = tk.Label(frame,
w.pack()
root.update()
root.mainloop()