Saturday, 22 January 2022

PythonSlip11a-Write Python GUI program to add menu bar with name of colors as options to change the background color as per selection from menu option.

 Write Python GUI program to add menu bar with name of colors as options to change the background color as per selection from menu option.  

import tkinter as tk

 def select():

    color = var.get()

    root['bg'] = color

  

root = tk.Tk()

 root.geometry("350x150")

 var = tk.StringVar(root)

# initial value

var.set('red')

 

choices = ['red', 'green', 'blue', 'yellow','white', 'magenta']

option = tk.OptionMenu(root, var, *choices)

option.pack(side='left', padx=10, pady=10)

 

button = tk.Button(root, text="check value slected", command=select)

button.pack(side='left', padx=20, pady=10)

 root.mainloop()