Advertisement
skip420

Dice

Aug 2nd, 2022
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. #import the required libraries
  2. #tkinter library to create GUI
  3. #random library because we're randomly selecting numbers
  4. from tkinter import *
  5. import random
  6.  
  7. #create tkinter instance
  8. root=Tk()
  9. #define geometry
  10. root.geometry("700x700")
  11.  
  12. #GUI will have two basic components
  13. #1.Button which will trigger the rolling of dice
  14. #2.Dice label
  15. l1=Label(root,font=("Helvetica",260))
  16.  
  17. def roll():
  18.     #create a number variable in which the list of all the ASCII characters of the string will be stored
  19.     #Use backslash because unicode must have a backslash
  20.     dice=['\u2680','\u2681','\u2682','\u2683','\u2684','\u2685']
  21.     #configure the label
  22.     l1.config(text=f'{random.choice(dice)}{random.choice(dice)}')
  23.     l1.pack()
  24.      
  25. b1=Button(root,text="Roll the Dice!",foreground='blue',command=roll)
  26. b1.place(x=0,y=0)
  27. b1.pack()
  28.  
  29. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement