Advertisement
Jump_off_a_cliff

Gui Dice Roller // Github Copilot

Jul 4th, 2022
917
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None
  1. # Importing the necessary modules
  2. import tkinter as tk
  3. import random
  4.  
  5. # Creating the main window
  6. root = tk.Tk()
  7. root.title("Dice Roller")
  8. root.geometry("300x300")
  9.  
  10. # Creating the label
  11. label = tk.Label(root, text="Dice Roller", font=("Arial", 20))
  12. label.pack()
  13.  
  14. label1 = tk.Label(root, text=0, font=("Arial", 20))
  15. label1.pack()
  16.  
  17.  
  18. # Creating the function to roll the dice
  19. def roll_dice():
  20.     # Generating a random number between 1 and 6
  21.     number = random.randint(1, 6)
  22.  
  23.     global label1
  24.     label1.config(text=number)
  25.  
  26.  
  27. # Creating the button
  28. button = tk.Button(root, text="Roll", command=roll_dice)
  29. button.pack()
  30.  
  31. # Running the main loop
  32. root.mainloop()
  33.  
Advertisement
RAW Paste Data Copied
Advertisement