В этом случае нажатие кнопки создает число, которое необходимо отобразить в GUI. Я пытаюсь сделать ролик для игры в кости, где все обрабатывается через Tkinter GUI и за пределами оболочки. На данный момент результат нажатия кнопок отображается в консоли, а не в созданной метке. У меня есть неполная этикетка, включенная в качестве пустого места, чтобы включить решение, когда оно у меня есть.
Заранее благодарим за помощь!
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()