Tkinter Widgets --> by myCODEnotein
Starter Template With Usual Methods
from tkinter import *
root = Tk()
root.geometry('1300x700')
root.title('')
root.mainloop()
Hoverable Button and events
Creating a button which changes colors on hover
from tkinter import *
root = Tk()
def ChangeBG(event,color):
event.widget.config(background=color)
# there are more ways of doing this
myButton = Button(root,text='Hoverable Button',bg='red',fg='white')
myButton.pack()
# When mouse enters the button
myButton.bind('<Enter>',func=lambda e:ChangeBG(e,'grey'))
# When mouse leaves the button
myButton.bind('<Leave>',func=lambda e:ChangeBG(e,'red'))
root.mainloop()
A Class For Making An Hoverable Button
class MyButton(Button):
def __init__(self,master,on_enter,**kwargs):
super().__init__(master,**kwargs)
'''
on_enter: a dictionary
# This specifies **options when mouse enters the
kwargs: a dictionary
# This specifies normal **options
'''
self.on_enter = on_enter
self.on_leave = kwargs
self.MakeHoverable() # changing the widget on hover
def MakeHoverable(self):
self.bind('<Enter>',lambda e:self.config(**self.on_enter))
self.bind('<Leave>',lambda e:self.config(**self.on_leave))
Adding a Scrollbar To Text widget (Full Template)
# Creating a text widget instance
myText = Text(master,**options)
myText.pack(side='left',expand=True,fill='both')
# Creating a scrollbar widget instance
myScroll = Scrollbar(master,command=myText.yview,**options)
myScroll.pack(side='right',expand=True,fill='y')
myText.config(yscrollcommand=myScroll.set)