Scrollregions 高度不会超过 4000

编程入门 行业动态 更新时间:2024-10-24 00:26:56
本文介绍了Scrollregions 高度不会超过 4000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的滚动区域高度不会超过 4000.当我将其设置为 10000 时,它不会改变高度.

My scrollregion height won't go any more than 4000. It doesn't change the height when I set it to 10000.

我尝试通过添加 100+ 来更改 Canvas 的高度

I've tried to change the Canvas height by adding 100+ to it

from tkinter import *
from tkinter import ttk
FrameU = Tk()


FrameNU=Frame(FrameU,width=540,height=800,bg="#A0522D")
FrameNU.place(x=0,y=0,relx=.2,rely=.2)

rx = .5
ry = .5

wCanvas, hCanvas = 550, 700   # size of canvas
w1, h1 = 0, 4000             # size of scrollable area

vBar = ttk.Scrollbar(FrameNU, orient = VERTICAL)
canvas_Main = Canvas(FrameNU,bg="#A0522D" ,scrollregion = (0,0,w1,h1), width = wCanvas, height = hCanvas, yscrollcommand = vBar.set)
vBar['command'] = canvas_Main.yview

vBar.pack(side=RIGHT,fill=Y)
canvas_Main.pack()

canvas_Main.create_line(10, 10, 100, 100)  #Test if it works
#Buttons setup below over 160... Only added 1
MS = Button(canvas_Main,height=3,width=6,bg="blue")

def VscrollBarMove(event):
    MS.place(relx = rx, rely = ry - vBar.get()[0]) 
    #... More placements just added one


vBar.bind('<B1-Motion>', VscrollBarMove)
mainloop()

没有错误.当我将高度从 4000 更改为 10000 时,它没有改变任何东西,但使滚动条看起来更小,好像它向下的区域更大,但事实并非如此.

No errors. When I changed the height from 4000 to 10000 it didn't change anything but made the scrollbar look smaller as if it had more area going down but it doesn't.

推荐答案

您的代码在 Python(和 Tkinter)语法的意义上是正确的.我稍微修改了它以证明它的正确性.(当然,所有新行都不是强制性的.)
1. 让我们全屏打开窗口:

Your code is correct in the sense of the Python (and the Tkinter) syntax. I modified it slightly to proof it's correctness. (Of course, all of new lines are not obligatory.)
1. Let's open the window to a full screen:

FrameU = Tk()   # The existing string
windowHeight = FrameU.winfo_screenheight()
windowWidth = FrameU.winfo_screenwidth()
FrameU.geometry('{}x{}'.format(windowWidth, windowHeight))
FrameU.state('zoomed')

2.我更改了第二帧的垂直位置以获得垂直滚动条的完整视图(在我当前的 1280 x 768 屏幕上):

2. I changed the vertical position of the second frame for full view of the vertical scrollbar (on my current 1280 x 768 screen):

FrameNU.place(x=0,y=0,relx=.2,rely=.05)  # the old rely was 0.2

3.大画布的新变量:

w1, h1 = 0, 4000    # size of scrollable area  # the exisiting string
h2 = 10000          # the new variable

我们使用这个新变量代替 h1:

canvas_Main = Canvas(FrameNU, ... ,scrollregion = (0,0,w1,h2), ... )  # Here h2 - the only change  

滚动条正确行为证明的参考线,正如 Bryan Oakley 所建议的那样. Reference lines for the scrollbar correct behavior proof, as Bryan Oakley adviced.

canvas_Main.create_line(10, h1-5, 100, h1-5, fill = 'green')  
canvas_Main.create_line(10, h2-5, 100, h2-5, fill = 'blue')   # before VscrollBarMove function definition

仅此而已.

这篇关于Scrollregions 高度不会超过 4000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:00:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高度   Scrollregions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!