[英]Python TK library horizontal scroll bar not showing
I am really new to TK library.我对 TK 库真的很陌生。 I have the following code, but horizontal scroll bar does not show.我有以下代码,但没有显示水平滚动条。 Can anyone see why?谁能明白为什么? Any help is appreciated!任何帮助表示赞赏!
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
container = ttk.Frame(root)
canvas = tk.Canvas(container)
scrollbar_y = ttk.Scrollbar(container, orient="vertical", command=canvas.yview)
scrollbar_x = ttk.Scrollbar(container, orient="horizontal", command=canvas.xview)
scrollable_frame = ttk.Frame(canvas)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
for i in range(50):
ttk.Label(scrollable_frame, text="Sample scrolling label").pack()
container.pack()
canvas.pack(side="left", fill="both", expand=True)
scrollbar_y.pack(side="right", fill="y")
scrollbar_x.pack(side="bottom", fill="x")
root.mainloop()
problem solved:问题解决了:
had to replace不得不更换
self.x_scrollbar = Scrollbar(self.container, orient="horizontal", command=self.canvas.xview)
with和
self.x_scrollbar = Scrollbar(self.master, orient="horizontal", command=self.canvas.xview)
So that the scrollbar can show up on the bottom instead of being buried in the frame.这样滚动条就可以显示在底部而不是埋在框架中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.