Artificial Intelligence
Please fill the required field.

crerate a GUI using python code in tkinter that first window has red square button that when click it will turn to blue and creates new window with green background, you can name the first window as ubuntu and the second window as kali no need for icon.


Sure! Below is a simple Python code using the Tkinter library to create the GUI as per your requirements. The first window (named "Ubuntu") contains a red square button that, when clicked, turns blue and opens a second window (named "Kali") with a green background. Make sure you have Python installed on your system along with Tkinter (which is included in standard distributions). You can run this code in a Python environment. Here is the code: ```python import tkinter as tk def on_button_click(): # Change the button color to blue button.config(bg='blue') # Create the second window (Kali) kali_window = tk.Toplevel() kali_window.title("Kali") kali_window.configure(bg='green') kali_window.geometry("300x200") # Set window size (optional) # Create the main window (Ubuntu) ubuntu_window = tk.Tk() ubuntu_window.title("Ubuntu") # Create a red square button button = tk.Button(ubuntu_window, bg='red', width=10, height=5, command=on_button_click) button.pack(pady=20) # Start the GUI main loop ubuntu_window.geometry("300x200") # Set window size (optional) ubuntu_window.mainloop() ``` ### Instructions to Run the Code: 1. Open your favorite text editor or IDE. 2. Copy and paste the provided code into a new file. 3. Save the file with a `.py` extension, e.g., `gui_example.py`. 4. Run the script using Python: ```bash python gui_example.py ``` ### Explanation of the Code: - The `on_button_click` function handles the button click event. It changes the button color to blue and creates a new window with a green background. - The main window (`ubuntu_window`) is created first, titled "Ubuntu", and contains a red button. - When the button is clicked, the color changes, and a new window (`kali_window`) is displayed with a green background. - The `mainloop()` method is called to run the application.