w3resource

Create a Python GUI window with custom background color

Python tkinter Basic: Exercise-11 with Solution

Write a Python GUI program that creates a window with a specific background color using Tkinter.

Sample Solution:

Python Code:

import tkinter as tk
# Create the main window
parent = tk.Tk()
parent.title("Window with Background Color")
# Set the background color of the window
parent.configure(bg="lightpink")  # Replace " lightpink" with your desired color
# Start the Tkinter event loop
parent.mainloop()

In the exercise above, we set the background color of the window by using the parent.configure(bg=" lightpink") line. Replace " lightpink" with the specific background color you want to use (you can use color names or hexadecimal color codes).

Sample Output:

Tkinter: Customize labels and buttons in Python Tkinter.

Flowchart:

Flowchart: Customize labels and buttons in Python Tkinter.

Python Code Editor:


Previous: Customize labels and buttons in Python Tkinter.
Next: Add an image to a Tkinter window in Python.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.