Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added random color generator button #7025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tkinter as tk
import random

# Function to generate a random color
def generate_random_color():
color = "#{:02x}{:02x}{:02x}".format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
color_label.config(text="Random Color: " + color)
canvas.config(bg=color)

# Create the main window
window = tk.Tk()
window.title("Random Color Generator")

# Create a button to generate a random color
generate_button = tk.Button(window, text="Generate Random Color", command=generate_random_color)
generate_button.pack(pady=10)

# Create a label to display the generated color
color_label = tk.Label(window, text="Random Color: ")
color_label.pack()

# Create a canvas to display the generated color as the background
canvas = tk.Canvas(window, width=200, height=200, bg="white")
canvas.pack()

# Start the Tkinter main loop
window.mainloop()
Loading