Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的滚动画布没有滚动,或者没有扩展包含框架的高度?_Python_Canvas_Tkinter_Scrollbar - Fatal编程技术网

Python 为什么我的滚动画布没有滚动,或者没有扩展包含框架的高度?

Python 为什么我的滚动画布没有滚动,或者没有扩展包含框架的高度?,python,canvas,tkinter,scrollbar,Python,Canvas,Tkinter,Scrollbar,更新:我添加了更多相关代码。对不起,遗漏了 下面是我想做的:我希望我的程序界面在主窗口的右侧包含一个滚动的画布。最终,这个画布应该独立滚动,我应该能够在上面粘贴小部件 我现在有一个很好的开始,但是,出于某种原因,画布既不会滚动,也不会延伸窗口的高度 我是新来的,所以我想请你对我的无知保持耐心。我已经大大缩短了代码,如果有什么需要补充的,请告诉我 class MainApplication(Frame): def __init__(self, master = None): '''We a

更新:我添加了更多相关代码。对不起,遗漏了

下面是我想做的:我希望我的程序界面在主窗口的右侧包含一个滚动的画布。最终,这个画布应该独立滚动,我应该能够在上面粘贴小部件

我现在有一个很好的开始,但是,出于某种原因,画布既不会滚动,也不会延伸窗口的高度

我是新来的,所以我想请你对我的无知保持耐心。我已经大大缩短了代码,如果有什么需要补充的,请告诉我

class MainApplication(Frame):
def __init__(self, master = None):
    '''We all know what this is.'''
    Frame.__init__(self, master)
    mixer.init()
    self.grid()
    self.master = master
    # Fullscreenness: from effbot.org
    w, h = root.winfo_screenwidth(), root.winfo_screenheight()
    root.geometry("%dx%d+0+0" % (w, h))
    root.grid_columnconfigure(0, weight = 3)
    self.window = Frame(self, relief = SUNKEN)
    self.window.grid(sticky = 'nsew')
    self._menuSetup()    # Generates the menubar
    self._windowSetup()  # Here is where the window is supposed to be

# There are a bunch of other methods skipped here

def _windowSetup(self):
    '''Sets the window up'''
    def onTickerConfigure(event):
        self.tickerCanvas.configure(scrollregion = self.tickerCanvas.bbox('all'))
    def setupRightTicker():
        '''Eventually, this will be a lot more complicated, but for now it just puts some stuff into the
        ticker.'''
        textOne = TickerEntry('Welcome to the Brew Manager!', self)
        textOne.grid(sticky = 'we')
        textTwo = TickerEntry('Your Brewery Needs to be Set Up', self, self.brewerySetup)
        textTwo.grid(sticky = 'we')
        for test in range(20):
            text = TickerEntry('This is a test entry '+str(test), self)
            text.grid(sticky = 'we')
        self.window.grid_columnconfigure(0, weight = 3)
    self.window.grid_columnconfigure(1, weight = 1, minsize = 100)
    self.rightTickerFrame = Frame(self.window, width = 100, relief = FLAT)
    self.noteFrame = Frame(self.window, width = 600, relief = FLAT)
    self.noteFrame.grid(row = 0, column = 0)
    self.rightTickerFrame.grid(row = 0, column = 1, sticky = 'nse', ipadx = 5, ipady = 5)
    self.rightTickerPad = Frame(self.rightTickerFrame, border = 0, height = 15, relief = FLAT)
    self.rightTickerPad.grid()        
    self.tickerBox = Frame(self.rightTickerFrame, border = 1, relief = FLAT, pad = 3)
    self.tickerBox.grid(sticky = 'nswe')
    self.tickerCanvas = Canvas(self.tickerBox, borderwidth = 0)
    self.ticker = Frame(self.tickerCanvas, borderwidth = 0)
    self.tickerScroll = Scrollbar(self.tickerBox, orient = 'vertical', command = self.tickerCanvas.yview())
    self.tickerCanvas.configure(yscrollcommand = self.tickerScroll.set)
    self.tickerScroll.pack(side = 'right', fill = 'y')
    self.tickerCanvas.pack(side = 'left', fill = 'both', expand = True)
    self.tickerCanvas.create_window((4,4), window = self.ticker, anchor = 'nw', tags = self.ticker)
    self.ticker.bind('<Configure>', onTickerConfigure)
    # Setup the Righthand Ticker
    setupRightTicker()
    # Setup the notebook
    noteWidth = root.winfo_screenwidth() - 300
    noteHeight = root.winfo_screenheight() - 110
    self.note = Notebook(self.noteFrame, width = noteWidth, height = noteHeight)
    self.note.grid(sticky = 'nsw')
类主应用程序(框架):
def uuu init uuu(self,master=None):
“我们都知道这是什么”
帧。\uuuu初始化(自,主)
mixer.init()
self.grid()
self.master=master
#完整屏幕:来自effbot.org
w、 h=root.winfo_屏幕宽度(),root.winfo_屏幕高度()
根几何体(“%dx%d+0+0”%(w,h))
root.grid\u columnconfigure(0,权重=3)
self.window=框架(self,relief=凹陷)
self.window.grid(粘性='nsew')
self._menuSetup()#生成菜单栏
self._windowSetup()#这里是窗口的位置
#这里跳过了许多其他方法
def_窗口设置(自):
''设置窗口''
def onTickerConfigure(事件):
self.tickerCanvas.configure(scrollregion=self.tickerCanvas.bbox('all'))
def setupRightTicker():
''最终,这将是一个更复杂的,但现在它只是把一些东西放进
股票行情
textOne=TickerEntry('欢迎使用Brew Manager!',self)
grid(sticky='we')
text2=TickerEntry('您的啤酒厂需要设置',self,self.brewerySetup)
textwo.grid(粘性='we')
对于范围内的试验(20):
text=TickerEntry('这是一个测试条目'+str(测试),self)
grid(sticky='we')
self.window.grid\u columnconfigure(0,权重=3)
self.window.grid\u columnconfigure(1,weight=1,minsize=100)
self.rightTickerFrame=Frame(self.window,宽度=100,浮雕=FLAT)
self.noteFrame=Frame(self.window,宽度=600,浮雕=FLAT)
self.noteFrame.grid(行=0,列=0)
self.rightTickerFrame.grid(行=0,列=1,粘性=nse',ipadx=5,ipady=5)
self.rightTickerPad=Frame(self.rightTickerFrame,边框=0,高度=15,浮雕=FLAT)
self.rightTickerPad.grid()
self.tickerBox=Frame(self.rightTickerFrame,border=1,relief=FLAT,pad=3)
self.tickerBox.grid(粘性='nswe')
self.tickerCanvas=Canvas(self.tickerBox,borderwidth=0)
self.ticker=Frame(self.tickerCanvas,borderwidth=0)
self.tickerScroll=Scrollbar(self.tickerBox,orient='vertical',command=self.tickerCanvas.yview())
self.tickerCanvas.configure(yscrollcommand=self.tickerScroll.set)
self.tickerScroll.pack(side='right',fill='y')
self.tickerCanvas.pack(side='left',fill='both',expand=True)
self.tickerCanvas.create_window((4,4),window=self.ticker,anchor='nw',tags=self.ticker)
self.ticker.bind(“”,onTickerConfigure)
#设置右侧的滴答器
setupRightTicker()
#设置笔记本
noteWidth=root.winfo_screenwidth()-300
noteHeight=root.winfo_屏幕高度()-110
self.note=笔记本(self.noteFrame,宽度=noteWidth,高度=noteWidth)
self.note.grid(粘性='nsw')
以下是我的代码当前生成的内容:

我的大部分代码都是基于我在这里找到的关于如何在Tkinter中创建滚动框的其他问题的东西(stackoverflow)。我确信我只是在做一些愚蠢的事情,但就我个人而言,我找不到它


其他人可以吗?

如果在画布中打包/放置/网格小部件,它们将不会滚动。您需要使用
create\u窗口
方法。如果使用
create\u window
添加小部件,则不会影响画布的大小。你不能同时得到两种行为,因为它们是矛盾的

我的建议是从头开始。从尽可能少的代码开始构建主窗口布局。添加画布和任何其他高级框架。给他们所有不同的颜色,这样你就可以看到一个小部件的结束和下一个小部件的开始。首先,您可能需要为框架设置一个人工尺寸。这样做,让你的应用程序的主要区域以你期望的方式出现和表现。调整窗口大小时,请确保所有内容都正确调整大小


然后,也只有到那时,才开始添加内部小部件。这样做意味着您不会试图同时解决多个布局问题。目前,您的问题可能在于如何管理内部小部件,或高层框架,或两者兼而有之

您没有向我们显示创建任何画布小部件或向画布添加任何内容的代码,并且您的代码有索引错误。@BryanOakley:很抱歉遗漏了此代码。我已经包含了相关代码。您仍然有缩进错误。但是我应该能够分配尺寸,不是吗?还是我忽略了什么?是的,你可以指定尺寸。如示例中所述,画布的请求宽度为1(一),高度为1,因为您没有为其指定明确的大小。它的最终大小取决于应用程序中的其他小部件。