I added scroll bar in a frame when the entry grid boxes exceeds the height of the frame. The scroll bar can be dragged and mouse wheel works when the cursor is hovering in the area of scroll bar but when the cursor is elsewhere, it doesn't work. How to make the scrolling possible when cursor is anywhere on the screen?
from tkinter import *
def data():
for i in range(50):
if (i % 2) == 0:
l4 = Label(frame, text="Size of rectangle:")
l4.grid(row=i, column=0)
en = Entry(frame)
en.grid(row=i, column=1)
b3 = Button(frame, text="Save")
b3.grid(row=51, column=0)
b4 = Button(frame, text="Back")
b4.grid(row=51, column=1)
def myfunction(event):
canvas.configure(scrollregion=canvas.bbox("all"),width=600,height=600)
root=Tk()
sizex = 650
sizey = 625
posx = 100
posy = 100
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
myframe=Frame(root,relief=GROOVE,width=200,height=200,bd=1)
myframe.place(x=20,y=20)
canvas=Canvas(myframe)
frame=Frame(canvas)
myscrollbar=Scrollbar(myframe,orient="vertical",command=canvas.yview)
canvas.configure(yscrollcommand=myscrollbar.set)
myscrollbar.pack(side="right",fill="y")
canvas.pack(side="left")
canvas.create_window((0,0),window=frame,anchor='nw')
frame.bind("<Configure>",myfunction)
data()
root.mainloop()