Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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 - Fatal编程技术网

Python-可通过文本调整的画布滚动条

Python-可通过文本调整的画布滚动条,python,canvas,tkinter,Python,Canvas,Tkinter,首先,我是一名法国学生,所以我不能说一口流利的英语 我遇到了一个问题,当我试图使我的画布的滚动条可调的数量取决于我的画布上的文本 如果画布中的文本对于屏幕来说太大,我需要滚动条 from tkinter import * from tkinter.filedialog import * from tkinter.messagebox import * from tkinter.scrolledtext import * def writeincanvas(): canvas.inser

首先,我是一名法国学生,所以我不能说一口流利的英语

我遇到了一个问题,当我试图使我的画布的滚动条可调的数量取决于我的画布上的文本

如果画布中的文本对于屏幕来说太大,我需要滚动条

from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from tkinter.scrolledtext import *

def writeincanvas():
    canvas.insert(canvas_id, 5000, "Hi !" + "\n")

win_crypt = Tk()
win_crypt.title("Canvas adjustable")

canvas = Canvas(win_crypt, width=960, background="white", scrollregion=(0,0,5000,5000))

### here is "scrollregion=(0,0,5000,50000)" but I don't 
### need that because I need auto-adjustable**

scroll = Scrollbar(win_crypt, orient=VERTICAL)
scroll.pack(side=RIGHT, fill=Y)
scroll.config(command=canvas.yview)

canvas.config(width=960, yscrollcommand=scroll.set)
canvas.pack(side=RIGHT, fill=BOTH)

canvas_id = canvas.create_text(10, 10, anchor="nw")

Label(win_crypt, text="Clic on the button :").pack(pady=20)
Button(win_crypt, text="Press !", command=writeincanvas).pack(pady=20)

win_crypt.mainloop()

canvas方法
bbox
返回作为参数传入的一个或多个项的边界框坐标。如果传入特殊参数
“all”
,它将返回适合所有内容的最小矩形的坐标。将项目添加到画布后,您可以将此值用于
滚动区域
属性

def writeincanvas():
    canvas.insert(canvas_id, 5000, "Hi !" + "\n")
    canvas.configure(scrollregion=canvas.bbox("all"))

很好,谢谢,它工作得很好。谢谢你引用我的文字,因为我不知道如何正确地做。但是你知道如何用鼠标选择文字吗?@Quentium:这与这个问题完全无关。如果你有其他问题,请点击“问问题”按钮。