Advertisement
HuanMatus

Untitled

Jun 18th, 2022
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. class Btn:
  4. def __init__(self, master, color, col_name):
  5. self.but = Button(master, bg = color, width = 25, text = col_name)
  6. self.but.pack()
  7.  
  8. self.but['command'] = self.pressed
  9. self.color = color
  10. self.col_name = col_name
  11.  
  12. def pressed(self):
  13. lbl['text'] = self.col_name
  14. ent.delete(0, END)
  15. ent.insert(0, self.color)
  16.  
  17. root = Tk()
  18. lbl = Label()
  19. lbl.pack()
  20.  
  21. ent = Entry()
  22. ent.pack()
  23.  
  24.  
  25.  
  26. Btn(root, '#ff0000', 'Красный')
  27. Btn(root, '#ffd700', 'Orange')
  28. Btn(root, '#ffff00', 'Yellow')
  29. Btn(root, '#00ff00', 'Green')
  30. Btn(root, '#007f00', 'Light Blue')
  31. Btn(root, '#0000ff', 'Blue')
  32. Btn(root, '#7f00ff', 'Violet')
  33.  
  34.  
  35.  
  36. root.mainloop()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement