Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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_Python 3.x_Tkinter - Fatal编程技术网

Python 如何修复滚动条,使其从上到下伸展?

Python 如何修复滚动条,使其从上到下伸展?,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我想在画布中创建一个框架,我需要能够滚动框架的内容 我知道滚动条不能添加到框架中,所以我正在创建一个画布,以便附加滚动条。但是,在创建滚动条时,它在一个角落中显示得越来越小。我需要一个解决方案来解决它。 因此,我希望在我的根屏幕以北的上中心有一个标签和一个滚动条,它应该能够滚动整个屏幕的内容。因为滚动条在第0行,画布在第1行。您必须使画布和滚动条在同一行中,但在两个不同的列中。试试这个: from tkinter import * root = Tk() root.geometry("100

我想在画布中创建一个框架,我需要能够滚动框架的内容

我知道滚动条不能添加到框架中,所以我正在创建一个画布,以便附加滚动条。但是,在创建滚动条时,它在一个角落中显示得越来越小。我需要一个解决方案来解决它。

因此,我希望在我的根屏幕以北的上中心有一个标签和一个滚动条,它应该能够滚动整个屏幕的内容。

因为滚动条在第0行,画布在第1行。您必须使画布和滚动条在同一行中,但在两个不同的列中。试试这个:

from tkinter import *

root = Tk()
root.geometry("1000x1000")
root.title("Title")

root.grid_rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=0)

canv = Canvas(root, width=600, height=600, background='blue')
vsb = Scrollbar(root, orient="vertical", command=canv.yview)
canv.config(yscrollcommand=vsb.set)
vsb.grid(row=0, column=1, sticky="ns")
canv.config(scrollregion=(0, 0, 600, 1000))
canv.grid(row=0, column=0)  # row = 0
canv.bind('<Configure>', canv.config(scrollregion=canv.bbox('all')))

root.mainloop()
from tkinter import *

root = Tk()
root.geometry("1000x1000")
root.title("Title")

root.grid_rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=0)

canv = Canvas(root, width=600, height=600, background='blue')
vsb = Scrollbar(root, orient="vertical", command=canv.yview)
canv.config(yscrollcommand=vsb.set)
vsb.grid(row=0, column=1, sticky="ns")
canv.config(scrollregion=(0, 0, 600, 1000))
canv.grid(row=0, column=0)  # row = 0
canv.bind('<Configure>', canv.config(scrollregion=canv.bbox('all')))

root.mainloop()