我有一个名为self.canvas_input_frame
的画布,其中的画布名为self.canvas_input_image
. self.canvas_input_image
是实际显示图像的位置。我已将子元素垂直和水平滚动条附加到self.canvas_input_frame
. 我的 GUI 如下图所示:
水平滚动条不完全从西向东延伸。如何解决?下面是我的代码:
def open_file_dialog(self):
self.filename = filedialog.askopenfilename(initialdir = "C:/Users/alyss/AppData/Local/Programs/Python/Python36/Damaged Text Document Virtual Restoration", title = "Select A File", filetype = (("png", "*.png"),("jpeg", "*.jpg"), ("pdf", "*.pdf"), ))
#Create Canvas Frame for Input Document
self.canvas_input_frame = tk.Canvas(self.main_canvas, bg = "blue")
self.canvas_input_frame.configure(width=456, height=470)
self.canvas_input_frame.pack(side="left", padx=10,pady = 10)
#Load Input Image
load = Image.open(self.filename)
render = ImageTk.PhotoImage(load)
self.width, self.height = load.size
self.canvas_input_image = tk.Canvas(self.canvas_input_frame,bg = "green") # how to render image in canvas
self.canvas_input_image.configure(width=390, height=470)
self.canvas_input_image.image = render
self.canvas_input_image.create_image(0,0,anchor="nw",image=self.canvas_input_image.image)
self.canvas_input_image.pack(side="left")
self.vsb_canvas_input_frame = tk.Scrollbar( self.canvas_input_frame, orient="vertical", command=self.canvas_input_image.yview)
self.hsb_canvas_input_frame = tk.Scrollbar( self.canvas_input_frame, orient="horizontal", command=self.canvas_input_image.xview)
self.canvas_input_image.config(yscrollcommand=self.vsb_canvas_input_frame.set,xscrollcommand=self.hsb_canvas_input_frame.set)
self.vsb_canvas_input_frame.pack(side = "right", fill = "y")
self.hsb_canvas_input_frame.pack(side = "bottom", fill = "x")
self.canvas_input_image.config(scrollregion = self.canvas_input_image.bbox("all"))
暮色呼如
相关分类