gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Hi, can you write a code that can change a background on python
- User
Hi, can you write a code that can change a background on python
- Assistant
Certainly! Here's a simple code snippet that changes the background color of a Python application using the tkinter library:
import tkinter as tk def change_background_color(color): root.config(bg=color) root = tk.Tk() # Create a label to demonstrate the background color change label = tk.Label(root, text="Background Color Demo", font=("Helvetica", 20)) label.pack(pady=30) # Create a list of colors to choose from colors = ['red', 'green', 'blue', 'yellow', 'orange'] # Create buttons for each color for color in colors: btn = tk.Button(root, text=color.title(), width=10, command=lambda color=color: change_background_color(color)) btn.pack() root.mainloop()This code creates a basic GUI window with a label and buttons for different colors. When you click on a button, the
change_background_color()function is called, which changes the background color of the window.