当输入网格框超过框架的高度时,我在框架中添加了滚动条。当光标悬停在滚动条区域时,可以拖动滚动条,并且鼠标滚轮可以工作,但是当光标位于其他位置时,它不起作用。当光标在屏幕上的任何位置时,如何使滚动成为可能?
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()