在canvas

时间:2015-08-17 14:40:53

标签: python tkinter scrollbars tkinter-canvas

以下计划:

import sys
import os
os.chdir('/Users/eduardomartinez/Desktop/artista')
sys.path.append('/Users/eduardomartinez/Desktop/Imaging-1.1.6')

from Tkinter import *
from PIL import Image, ImageTk

root = Tk()

im = Image.open('samples.png')
imtk = ImageTk.PhotoImage(im)

imageframe = Frame(root)

canvas = Canvas(imageframe)
canvas.create_image(0, 0, image=imtk, anchor="nw")
print canvas.bbox('all')
canvas.config(scrollregion=canvas.bbox('all'))
scrollx = Scrollbar(imageframe, orient=HORIZONTAL)
scrolly = Scrollbar(imageframe, orient=VERTICAL)
scrollx.config(command=canvas.xview)
scrolly.config(command=canvas.yview)

canvas.grid(column=0, row=0, sticky=W+E+N+S)

w = imtk.width()
h = imtk.height()
cw = canvas.winfo_width()
ch = canvas.winfo_height()
if w > cw:
        scrollx.grid(column=0, row=1, sticky=W+E)
if h > ch:
        scrolly.grid(column=1, row=0, sticky=N+S)

imageframe.columnconfigure(index=0, weight=1)
imageframe.rowconfigure(index=0, weight=1)

imageframe.pack()
root.mainloop()

抛出错误,如:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1570, in yview
res = self.tk.call(self._w, 'yview', *args)
TclError: unknown option "0": must be moveto or scroll

每当我尝试垂直滚动时(水平滚动时类似的错误)。我做错了什么?

(是的,stackoverflow机器人警察,我的帖子主要是代码。我不认为这个段落,旨在平衡我的帖子以符合你的指导方针,改善了任何事情)

0 个答案:

没有答案