Advertisement
here2share

# Tk_custom_button.py

Jul 21st, 2022
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # Tk_custom_button.py
  2.  
  3. from tkinter import *
  4.  
  5. canvas = Canvas(width=200, height= 200, borderwidth=3, relief="raised", highlightthickness=0)
  6.  
  7. padding = 10
  8. width = 200
  9. height = 200
  10.  
  11. c = canvas.create_oval((padding,padding,
  12.     width-padding, height-padding), outline='lightblue', fill='orange', width=10, tags='btn')
  13. canvas.create_text((102,100), text='Click Me!', font=("Verdana", 25), fill='black', tags='btn')
  14.  
  15. def _on_press(event):
  16.     canvas.configure(relief="sunken")
  17.     canvas.coords(c, [i+5 for i in canvas.coords(c)])
  18.  
  19. def _on_release(event):
  20.     canvas.configure(relief="raised")
  21.     canvas.coords(c, [i-5 for i in canvas.coords(c)])
  22.     print('hello')
  23. canvas.bind("<ButtonPress-1>", _on_press)
  24. canvas.bind("<ButtonRelease-1>", _on_release)
  25. canvas.pack()
  26.            
  27. canvas.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement