我有一个带有2个滚动区域的应用程序。第一个(主)是包含所有内容的根窗口。第二个(sub)在第一个(sub)中,并包含一些文本。
主滚动条工作正常,但是,每当我尝试滚动时,第二个滚动条似乎试图调整其自身大小。这会导致故障移动,闪烁,最后,它实际上可能会以较大的尺寸停止,直到重新配置为止。
我正在寻找通过代码更改或其他我可以使用的支持手动和鼠标滚轮滚动的tkinter模块解决此问题的方法。
代码:
from Tkinter import *
class GUI:
def __init__(self):
self.root = Tk()
self.main()
def update_scrollregion(self, event, can): ##the default option for interacting with scrollbar
can.configure(scrollregion=can.bbox("all"))
def main(self):
self.root.geometry("400x300")
##Start Of Layout
main_canvas=Canvas(self.root)
main_subframe=Frame(main_canvas)
main_vbar=Scrollbar(main_canvas,orient=VERTICAL, command=main_canvas.yview)
main_canvas.config(yscrollcommand=main_vbar.set)
main_vbar.pack(side=RIGHT,fill=Y)
main_canvas.pack(side=TOP,expand=True,fill=BOTH)
main_canvas.create_window((4,4), window=main_subframe, anchor = NW, tags="frame")
main_subframe.bind("<Configure>", lambda e=Event(), c=main_canvas: self.update_scrollregion(e, c))
for i in range(5): ##make some other objects to make the page bigger
Label(main_subframe, text="This is some beginning spacer text").pack(side=TOP)
##Main Issues are here with glitch size updates when calling the update_scrollregion method it attments to resize the canvas/subframe
mytext = 'This is a Test\r\n ' * 30 ##some multi line text
canvas=Canvas(main_subframe)
subframe=Frame(canvas)
vbar=Scrollbar(canvas,orient=VERTICAL, command=canvas.yview)
canvas.config(yscrollcommand=vbar.set)
vbar.pack(side=RIGHT,fill=Y)
canvas.pack(side=TOP,expand=True,fill=BOTH)
canvas.create_window((4,4), window=subframe, anchor = NW, tags="frame")
subframe.bind("<Configure>", lambda e=Event(), c=canvas: self.update_scrollregion(e, c))
Label(subframe, text=mytext, bg="red").pack(fill=BOTH, expand=1)
##------------------------------
for i in range(5): ##some more objects to make the page bigger
Label(main_subframe, text="This is some ending spacer text").pack(side=TOP)
self.root.mainloop()
GUI()