Tkinter滚动条不滚动 [英] Tkinter Scrollbar not scrolling

查看:356
本文介绍了Tkinter滚动条不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码正在创建一个带有内部按钮的可滚动Tkinter画布.我相信滚动条和Canvas的配置是可以的,但是当我运行该程序时,滚动条不会滚动.我已经在网上查看了其他解决方案,并且我相信我会满足应应用的所有要求.

I have some code which is creating a scrollable Tkinter canvas with buttons inside. I believe my configuration of the scrollbar and Canvas is ok, but when I run the program, the scrollbar does not scroll. I have looked at other solutions online and I believe I am fulfilling everything that should be applied.

感谢您提供的所有帮助:)

Thank you for any and all help:)

from tkinter import *

root = Tk()


responsesFr = Frame(root, width=700, height=275, bg="#d40b04")
responseFrCoverCanvas = Canvas(root, width=700,height=14 ,highlightthickness=0, border=0,bg="#d40b04")
w = Canvas(responsesFr, width=650, height=225, borderwidth=0,highlightthickness=0,background="white")
w.config(scrollregion=[0,0,1000,225])

for column in range(30):
    button1 = Button(w, width=20, height=4)
    button1.pack(side='left', padx=25)
    if column == 29:
        w.config(scrollregion=[0,0,1000,1000])
        print("done")
    else:
        pass
w.pack(padx=25,pady=10)
hbar=Scrollbar(responsesFr, orient=HORIZONTAL)
hbar.pack(padx=25, side=TOP, fill=X)
hbar.config(command=w.xview)
w.config(xscrollcommand=hbar.set)

responsesFr.pack()


root.mainloop()

推荐答案

您无法滚动使用pack添加的内容.您必须使用canvas create_window方法将小部件添加到画布.

You can't scroll things added with pack. You must use the canvas create_window method to add widgets to the canvas.

这篇关于Tkinter滚动条不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆