Odpowiedź :
import tkinter as tk
from tkinter import messagebox
import random
class App(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.master = master
self.master.title("Rzut kostką. Autor: bodyno")
self.master.geometry("300x200")
self.master.configure(bg="#a1dbcd")
self.create_widgets()
def create_widgets(self):
self.dice_label = tk.Label(self.master, text="Kostka", bg="#a1dbcd")
self.dice_label.grid(row=0, column=0, sticky=tk.W)
self.dice_entry = tk.Entry(self.master, width=5, bg="#a1dbcd")
self.dice_entry.grid(row=0, column=1, sticky=tk.W)
self.roll_button = tk.Button(self.master, text="Rzuć", width=10, command=self.roll_dice, bg="#a1dbcd")
self.roll_button.grid(row=1, column=0, sticky=tk.W)
self.quit_button = tk.Button(self.master, text="Zakończ", width=10, command=self.master.destroy, bg="#a1dbcd")
self.quit_button.grid(row=1, column=1, sticky=tk.W)
def roll_dice(self):
dice = self.dice_entry.get()
if dice == "K4":
result = random.randint(1, 4)
elif dice == "K8":
result = random.randint(1, 8)
elif dice == "K12":
result = random.randint(1, 12)
elif dice == "K20":
result = random.randint(1, 20)
elif dice == "K100":
result = random.randint(1, 100)
else:
result = "Nieprawidłowa kostka"
messagebox.showinfo("Wynik", result)
root = tk.Tk()
app = App(root)
app.mainloop()