Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 在画布中实现滚动条_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x 在画布中实现滚动条

Python 3.x 在画布中实现滚动条,python-3.x,tkinter,Python 3.x,Tkinter,所以我想在Tkinter的大型机上实现一个滚动条,但是这是不可能的,因此我必须使用Canvas。使用canvas,我能够实现一个滚动条并相应地使用其他小部件。在我尝试将小部件添加到画布之前,一切都很顺利 出现错误:滚动条看起来不正常,无法滚动 那么,我做错了什么?我该如何修复它 代码(Python 3.8.2) 注意:我只想添加其他小部件,包括仅使用grid manager添加的滚动条 #1画布中的框架 #2绑定一个事件(配置),该事件通过滚动更改画布视图内容 #3使用给定的框架创建一个窗口 f

所以我想在Tkinter的大型机上实现一个滚动条,但是这是不可能的,因此我必须使用Canvas。使用canvas,我能够实现一个滚动条并相应地使用其他小部件。在我尝试将小部件添加到画布之前,一切都很顺利

出现错误:滚动条看起来不正常,无法滚动

那么,我做错了什么?我该如何修复它

代码(Python 3.8.2)

注意:我只想添加其他小部件,包括仅使用grid manager添加的滚动条

#1画布中的框架

#2绑定一个事件(配置),该事件通过滚动更改画布视图内容

#3使用给定的框架创建一个窗口

from tkinter import *

root = Tk()
root.geometry("950x600")

# create canvas
canvas = Canvas(root, width=932, height=600, borderwidth=0, highlightthickness=0, bg="black")
vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
# create a scrollbar
f=Frame(canvas)#1
canvas.grid()
canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))#2
canvas.create_window((0,0),anchor='nw',window=f,width=932)#3
vsb.grid(row=0, column=1, sticky='ns')
# Test the ability to scroll
for x in range(300):
    Label(f, text="test").grid(row=x)

root.mainloop()
从tkinter导入*
root=Tk()
根几何体(“950x600”)
#创建画布
画布=画布(根,宽度=932,高度=600,边框宽度=0,highlightthickness=0,bg=“黑色”)
vsb=滚动条(root,orient=“vertical”,command=canvas.yview)
configure(yscrollcommand=vsb.set)
#创建一个滚动条
f=框架(画布)#1
canvas.grid()
canvas.bind(“,lambda e:canvas.configure(scrollregion=canvas.bbox(“全部”))#2
canvas.create_window((0,0),anchor='nw',window=f,width=932)#3
网格(行=0,列=1,粘性=ns')
#测试滚动的能力
对于范围(300)内的x:
标签(f,text=“test”).grid(行=x)
root.mainloop()
from tkinter import *

root = Tk()
root.geometry("950x600")

# create canvas
canvas = Canvas(root, width=932, height=600, borderwidth=0, highlightthickness=0, bg="black")
vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
# create a scrollbar
f=Frame(canvas)#1
canvas.grid()
canvas.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))#2
canvas.create_window((0,0),anchor='nw',window=f,width=932)#3
vsb.grid(row=0, column=1, sticky='ns')
# Test the ability to scroll
for x in range(300):
    Label(f, text="test").grid(row=x)

root.mainloop()