Створіть програму, у якій вікно змінюватиме колір фону на зелений після клацання лівою кнопкою миші й на червоний клацання правою. Питон
Ответы
from tkinter import *
root = Tk()
def change_bg_color(event):
if event.num == 1: # Left mouse button clicked
root.configure(background='green')
elif event.num == 3: # Right mouse button clicked
root.configure(background='red')
root.bind('<Button>', change_bg_color) # Bind the function to the left and right mouse clicks
root.mainloop()
Можна еще так сделать
from tkinter import *
root = Tk()
def left_mouse(event): # Left mouse button clicked
root.configure(background='green')
def right_mouse(event): # Right mouse button clicked
root.configure(background='red')
root.bind('<Button-1>', left_mouse) # Bind the function to the left mouse click
root.bind('<Button-3>', right_mouse) # Bind the function to the right mouse click
root.mainloop()
Відповідь:
from tkinter import *
root = Tk()
def change_bg_color(event):
if event.num == 1: # Left mouse button clicked
root.configure(background='green')
elif event.num == 3: # Right mouse button clicked
root.configure(background='red')
root.bind('<Button>', change_bg_color) # Bind the function to the left and right mouse clicks
root.mainloop()
Пояснення:
я не копіювала просто програмістка