降低 CustomTKinter (Python) 中可滚动框架的高度

问题描述 投票:0回答:2

嘿伙计们,

有没有办法将customtkinter库中CTkScrollableFrame的高度设置为200像素以下?

简短示例:

import customtkinter as ctk

root = ctk.CTk()
frame = ctk.CTkScrollableFrame(root, height=100)
frame.pack()
root.mainloop()

命令

height=100
似乎没有效果。如果我选择大于 200 的值,结果会变大,但我找不到办法让它变小。

我也尝试过

.grid
而不是
.pack
但它没有改变任何东西。

提前致谢。

python user-interface tkinter scrollview customtkinter
2个回答
0
投票

为了更改可滚动框架的高度,您需要使用

frame.configure()

这是代码:

import customtkinter as ctk

root = ctk.CTk()
frame = ctk.CTkScrollableFrame(root)
frame.pack()

# The height configure thing
frame.configure(height=100)

root.mainloop()

如果有效的话别忘了给我点赞:)


0
投票

customtkinter
小部件内部滚动条的默认高度为200,是
CTkScrollableFrame
的一个设计错误。

解决方法是在创建

frame._scrollbar.configure(height=0)
后调用
frame
显式设置内部滚动条的高度。

import customtkinter as ctk

root = ctk.CTk()
frame = ctk.CTkScrollableFrame(root, height=100)
# set the height of the internal scrollbar to zero
# then it will be expanded vertically to the configured height of "frame"
frame._scrollbar.configure(height=0)
frame.pack()
root.mainloop()
© www.soinside.com 2019 - 2024. All rights reserved.