Tuesday, 30 July 2024

 MYM-A MODO DADOROJO



import tkinter as tk

import threading

import time

import random


# Function to start the loading animation and display the dice result

def roll_dice():

    def loading_animation():

        loading_text = ["", ".", "..", "..."]

        for _ in range(3):

            for text in loading_text:

                display_var.set(text)

                time.sleep(0.5)


    # Run the loading animation

    loading_animation()


    # Display the dice result

    dice_result = random.randint(1, 3)

    display_var.set(dice_result)


    if dice_result == 3:

        display_confetti()

        root.after(10000, enable_button)  # Re-enable after 10 seconds for celebration

    else:

        root.after(500, enable_button)  # Re-enable shortly after result display


# Function to handle button click event

def on_button_click():

    threading.Thread(target=roll_dice).start()

    click_button.config(state="disabled")


# Function to enable the button

def enable_button():

    click_button.config(state="normal")


# Function to display confetti

def display_confetti():

    confetti = ["🎉", "🎊", "🎈"]

    for _ in range(10):  # Number of confetti flashes

        for c in confetti:

            display_var.set(c)

            time.sleep(0.1)

        display_var.set("3")

        time.sleep(0.1)


# Initialize the main window

root = tk.Tk()

root.title("3 FACE DICE")

root.geometry("300x200")


# Create the UI elements

title_label = tk.Label(root, text="3 FACE DICE", font=("Helvetica", 16))

title_label.pack(pady=10)


display_var = tk.StringVar()

display_label = tk.Label(root, textvariable=display_var, font=("Helvetica", 24), width=5, height=2, relief="solid")

display_label.pack(pady=20)


click_button = tk.Button(root, text="Click", font=("Helvetica", 14), command=on_button_click)

click_button.pack(pady=10)


# Start the Tkinter event loop

root.mainloop()


No comments:

Post a Comment

https://youtu.be/jZ38C-M3tyk?si=ERjuJ8hqsQwV2vAp