两侧可滚动框架,用于双向按钮列表 - Customtkinter

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

我在页面类中有一个框架,其中有 10x10 按钮和条目小部件如何使框架在 python tkinter 中双向滚动。

画布无法工作,因为我无法在画布上放置按钮。请在这方面提供帮助。

customtkinter
1个回答
0
投票

我使用画布并将按钮放置在那里! :)

import customtkinter

# Creating app
app = customtkinter.CTk()
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1)

# Creating Canvas
canvas1 = customtkinter.CTkCanvas(app, highlightthickness=0)
canvas1.grid(row=0, column=0, sticky="nsew")

# Creating Scrollbars
scroll_vertical = customtkinter.CTkScrollbar(app, width=15, command=canvas1.yview)
scroll_vertical.grid(row=0, column=1, sticky="ns")

scroll_horizontal = customtkinter.CTkScrollbar(app, height=15, command=canvas1.xview)
scroll_horizontal.grid(row=1, column=0, sticky="ew")

# Linking the scrollbars to the canvas
canvas1.configure(yscrollcommand=scroll_vertical.set)
canvas1.configure(yscrollcommand=scroll_horizontal.set)

# Creating buttons and placing them in the Canvas
button1 = customtkinter.CTkButton(canvas1, text="Hello!")
button1.grid(row=0, column=0)

button2 = customtkinter.CTkButton(canvas1, text="Hello again!")
button2.grid(row=0, column=1)

app.mainloop()
© www.soinside.com 2019 - 2024. All rights reserved.