简体   繁体   English

Tkinter程序:没有显示底部滚动条

[英]Tkinter program: doesn't show me the bottom scrollbar

Here is my Tkinter code. 这是我的Tkinter代码。 I intend to show the both horizontal and vertical scrollbar. 我打算同时显示水平和垂直滚动条。

from Tkinter import *

root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT,fill = Y)

scrollbar_x = Scrollbar(root)
scrollbar_x.pack(side = BOTTOM,fill = X)

mylist = Listbox(root,xscrollcommand = scrollbar_x.set,yscrollcommand = scrollbar.set)
"""
To connect a scrollbar to another widget w, set w's xscrollcommand or yscrollcommand to the scrollbar's set() method. The arguments have the same meaning as the values returned by the get() method.
"""
for line in range(100):
    mylist.insert(END,("this is line number"+str(line))*100)

mylist.pack(side = LEFT,fill=BOTH)

scrollbar.config(command = mylist.yview)
scrollbar_x.config(command = mylist.xview)

print root.pack_slaves()
mainloop()

And it doesn't match up to my expectation in my computer, which is Mac Sierra. 而且它与我的计算机Mac Sierra达不到我的期望。 Furthermore, what's scrollbar.config(command = mylist.yview) means? 此外, scrollbar.config(command = mylist.yview)是什么意思?

config()

More details about this function will be helpful~ thanks 有关此功能的更多详细信息将有所帮助〜谢谢

Tkinter program: doesn't show me the bottom scrollbar Tkinter程序:没有显示底部滚动条

I can't duplicate that when I run your code. 运行您的代码时,我无法重复该操作。 When I run your code I see a giant scrollbar at the bottom of the screen. 运行代码时,我在屏幕底部看到一个巨大的滚动条。

I presume you want the "x" scrollbar to be horizontal rather than vertical. 我假设您希望“ x”滚动条是水平的而不是垂直的。 If that is true, you must tell tkinter that by using the orient option: 如果是这样,则必须使用orient选项告诉tkinter:

scrollbar_x = Scrollbar(root, orient="horizontal")

Furthermore, what's scrollbar.config(command = mylist.yview) means? 此外,scrollbar.config(command = mylist.yview)是什么意思?

Scrollbars require two-way communication. 滚动条需要双向通讯。 The listbox needs to be configured to know which scrollbar to update when it has been scrolled, and the scrollbar needs to be configured such that it knows which widget to modify when it is moved. 列表框需要配置为在滚动时知道要更新的滚动条,并且滚动条需要进行配置以使其知道在移动时要修改的窗口小部件。

When you do scrollbar.config(command=mylist.yview) you are telling the scrollbar to call the function mylist.yview whenever the user tries to adjust the scrollbar. 当您执行scrollbar.config(command=mylist.yview)您告诉滚动条在用户尝试调整滚动条时调用函数mylist.yview The .yview method is a documented method on the Listbox widget (as well as a few others). .yview方法是Listbox小部件(以及其他一些方法)上的一种记录方法。 If you do not set the command attribute of a scrollbar, interacting with the scrollbar will have no effect. 如果未设置滚动条的command属性,则与滚动条的交互将无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM