MYM-A MODO DADOCASIO 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:
message_label.config(text="Click Connect")
root.after(10000, reset) # Re-enable after 10 seconds for celebration
else:
root.after(500, enable_button) # Re-enable shortly after result display
# Function to reset the display and button after celebration
def reset():
message_label.config(text="")
display_var.set("")
enable_button()
# 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 automatically click the button every 10 seconds
def auto_click():
while True:
time.sleep(10)
if click_button["state"] == "normal": # Ensure it only clicks if button is enabled
root.after(0, on_button_click) # Use root.after to schedule the click in the main thread
# Initialize the main window
root = tk.Tk()
root.title("3 FACE DICE")
root.geometry("300x250")
# 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)
message_label = tk.Label(root, text="", font=("Helvetica", 14), fg="green")
message_label.pack(pady=10)
# Start the automatic clicking in a separate thread
threading.Thread(target=auto_click, daemon=True).start()
# Start the Tkinter event loop
root.mainloop()
No comments:
Post a Comment