【发布时间】:2016-07-07 00:27:04
【问题描述】:
我正在尝试创建一个带有两个画布和一个滚动条同时通过两者的 gui,作为对另一个项目的测试。我已经创建了根、两个画布并使用 grid 方法将一些标签固定到每个画布上,并创建了滚动条。
但是,当我运行程序时,滚动条移动得很好,但窗口的内容根本没有改变,就好像滚动条不工作一样。我已经通过谷歌搜索我的问题尝试了一些解决方案,但到目前为止我还没有能够解决它。
相关代码是
from tkinter import *
root = Tk()
#scroll
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
firstCanvas = Canvas(root, width=200, height=100)
firstCanvas.pack(side="left", fill="both", expand=True)
secondCanvas = Canvas(root, width=20000, height=10000,scrollregion=(0,0,0,5000),yscrollcommand=scrollbar.set)
secondCanvas.pack(side="left", fill="both", expand=True)
secondCanvas.create_rectangle((200,300,300,6000))
widget = Label(firstCanvas, text='Spam')
widget.pack()
# Lots of widgets so they reach beyond the screen, all in the following format
widgetOne=Label(firstCanvas, text="this is a test")
widgetOne.pack()
widgetTwo=Entry(firstCanvas)
widgetTwo.pack()
widgetThree=Label(secondCanvas, text='Spam')
widgetFour=Entry(secondCanvas)
widgetFour.pack()
scrollbar.config(command=secondCanvas.yview)
mainloop()
【问题讨论】: