爲什麼文本構件沒有填充整個黃色框架? 還送了我肯定讓文本組件粘? - 我錯過什麼`使文本構件填充框架
(can_frame
短的canvas_frame - 這個名字我給我的推杆到畫布
from tkinter import *
enter code here
class window:
def __init__(self, root):
root.grid_rowconfigure (0, weight=1)
root.grid_columnconfigure(1, weight=1)
self.frame = Frame(root)
self.frame.grid(row=0, column=1, sticky='nsew')
self.frame.grid_columnconfigure(0, weight=1)
self.frame.grid_rowconfigure(0, weight=1)
self.canvas = Canvas(self.frame)
self.can_frame = Frame(self.canvas, bg='yellow')
self.canvas.grid( row=0, column=0, sticky='nsew')
self.can_frame.grid(row=0, column=0, sticky='nsew')
self.canvas.grid_columnconfigure((0,1), weight=1)
self.canvas.grid_rowconfigure( (0,1), weight=1)
self._frame_id = self.canvas.create_window((1,1), window=self.can_frame, anchor='sw', tags="self.frame")
self.canvas.bind( '<Configure>', self.resize_frame)
self.can_frame.bind('<Configure>', self.onFrameConfigure)
inp = Text(self.can_frame, width=40, relief='groove') # TEXT WIDGET CREATED HERE
inp.grid(row=0, column=0, sticky='nsew') # it's sticky so why isn't it filling out the -
# - yellow frame?
def resize_frame(self, e):
self.canvas.itemconfig(self._frame_id, height=e.height, width=e.width)
def onFrameConfigure(self, e):
# update scrollregion after starting 'mainloop'
# when all widgets are in canvas
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
框架
請不要發佈沒有任何帆布解決方案,我需要的畫布後上創建一個滾動條,以便通過所有不同的文本小部件的滾動。 謝謝!
代碼的縮進被打破。 –
爲什麼要將文本小部件放在畫布中的一個框架中?這非常不尋常。 –