使用 python 3.2.2 tkinter 我创建了一个带有滚动条的画布,但是当我移动滚动条时画布内的数据不会滚动。tkinter 的语法问题或错误?
示例代码:
from tkinter import *
## GUI color map ###
black = "#000000"
root = Tk()
root.minsize(100,100)
root.maxsize(500,500)
root.resizable(0,0)
topFrame = Frame(root, bd=2, relief=SUNKEN)
topFrame.pack()
xscrollbar = Scrollbar(topFrame, orient=HORIZONTAL)
xscrollbar.pack(side=BOTTOM, fill=X)
yscrollbar = Scrollbar(topFrame, orient=VERTICAL)
yscrollbar.pack(side=RIGHT, fill=Y)
conFrame = Canvas(topFrame, bd=0, scrollregion=(0, 0, 1000, 1000),
xscrollcommand=xscrollbar.set,
yscrollcommand=yscrollbar.set)
conFrame.pack(side=TOP, fill=BOTH, expand=1)
xscrollbar.config(command=conFrame.xview)
yscrollbar.config(command=conFrame.yview)
for i in range(1,30):
function_name = 'my'+str(i)+'ItemList = StringVar()'
exec(function_name)
function_name = 'my'+str(i)+'Item = '+str(i)
exec(function_name)
function_name = 'my'+str(i)+'ItemList.set(my'+str(i)+'Item)'
exec(function_name)
function_name = 'my'+str(i)+'ItemListEntry = Entry(conFrame, width=148, foreground=black, textvariable=my'+str(i)+'ItemList)'
exec(function_name)
function_name = 'my'+str(i)+'ItemListEntry.pack(side=TOP, padx=2)'
exec(function_name)
mainloop()