Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import tkinter as tk
- from random import randint
- from tkinter import messagebox
- def roll_die(sides):
- n = randint(1, sides)
- messagebox.showinfo(title='Liczba to:', message=n)
- class GUI:
- def __init__(self, master):
- self.master = master
- self.draw_buttons()
- def draw_buttons(self):
- dice_sides = [4, 6, 8, 12, 20, 100]
- for n in dice_sides:
- button = tk.Button(self.master,
- text='Wylosuj kostka {}'.format(n),
- command=lambda: roll_die(n))
- button.pack()
- quit_button = tk.Button(self.master,
- text='Koniec',
- command=sys.exit)
- quit_button.pack()
- root = tk.Tk()
- gui = GUI(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement