Sunday, 23 January 2022

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.

Slip 11 Q 2

CODE :

from tkinter import Menu, Tk, mainloop

def redcolor():
    root.configure(background = 'red')
def greencolor():
    root.configure(background = 'green')
def yellowcolor():
    root.configure(background = 'yellow')
def violetcolor():
    root.configure(background = 'violet')
def bluecolor():
    root.configure(background = 'blue')
def cyancolor():
    root.configure(background = 'cyan')
   
root = Tk()
root.title('COLOR MENU')

menubar = Menu(root)

color = Menu(menubar, tearoff = 0)
menubar.add_cascade(label ='color', menu = color)
color.add_command(label ='Red', command = redcolor,activebackground='red',
                    activeforeground='cyan')

color.add_command(label ='Green',command = greencolor,activebackground='green',
                    activeforeground='blue')

color.add_command(label ='Blue',command = bluecolor,activebackground='blue',
                    activeforeground='yellow')

color.add_command(label ='Yellow',command = yellowcolor,activebackground='yellow',
                    activeforeground='blue')

color.add_command(label ='Cyan',command = cyancolor,activebackground='cyan',
                    activeforeground='red')

color.add_command(label ='Violet',command = violetcolor,activebackground='violet',
                    activeforeground='green')
color.add_separator()
color.add_command(label ='Exit',command = root.destroy)


root.config(menu = menubar)
mainloop()

Output :






No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...