Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Importing the necessary modules
- import tkinter as tk
- import random
- # Creating the main window
- root = tk.Tk()
- root.title("Dice Roller")
- root.geometry("300x300")
- # Creating the label
- label = tk.Label(root, text="Dice Roller", font=("Arial", 20))
- label.pack()
- label1 = tk.Label(root, text=0, font=("Arial", 20))
- label1.pack()
- # Creating the function to roll the dice
- def roll_dice():
- # Generating a random number between 1 and 6
- number = random.randint(1, 6)
- global label1
- label1.config(text=number)
- # Creating the button
- button = tk.Button(root, text="Roll", command=roll_dice)
- button.pack()
- # Running the main loop
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement