Advertisement
CodeCrusader

GUI Dice Roller

Jun 10th, 2023 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | Software | 0 0
  1. import tkinter as tk
  2. import random
  3.  
  4. # Initialize the window
  5. window = tk.Tk()
  6. window.title("Dice Roll")
  7. window.geometry("200x300")
  8.  
  9. # Create a label to display the dice face
  10. dice_label = tk.Label(window, font=("Helvetica", 100), padx=50, pady=50)
  11. dice_label.pack()
  12.  
  13. # Function to roll the dice
  14. def roll_dice():
  15.     dice_faces = ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
  16.     dice_face = random.choice(dice_faces)
  17.     dice_label.config(text=dice_face)
  18.  
  19. # Create a button to roll the dice
  20. roll_button = tk.Button(window, text="Roll", command=roll_dice)
  21. roll_button.pack()
  22.  
  23. window.mainloop()
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement