Advertisement
Guest User

Untitled

a guest
May 14th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import sys
  2. import tkinter as tk
  3.  
  4. from random import randint
  5. from tkinter import messagebox
  6.  
  7. def roll_die(sides):
  8.   n = randint(1, sides)
  9.   messagebox.showinfo(title='Liczba to:', message=n)
  10.  
  11. class GUI:
  12.   def __init__(self, master):
  13.     self.master = master
  14.     self.draw_buttons()
  15.  
  16.   def draw_buttons(self):
  17.     dice_sides = [4, 6, 8, 12, 20, 100]
  18.     for n in dice_sides:
  19.       button = tk.Button(self.master,
  20.                          text='Wylosuj kostka {}'.format(n),
  21.                          command=lambda: roll_die(n))
  22.       button.pack()
  23.  
  24.     quit_button = tk.Button(self.master,
  25.                             text='Koniec',
  26.                             command=sys.exit)
  27.     quit_button.pack()
  28.  
  29. root = tk.Tk()
  30. gui = GUI(root)
  31. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement