簡體   English   中英

Tkinter程序:沒有顯示底部滾動條

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

這是我的Tkinter代碼。 我打算同時顯示水平和垂直滾動條。

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()

而且它與我的計算機Mac Sierra達不到我的期望。 此外, scrollbar.config(command = mylist.yview)是什么意思?

config()

有關此功能的更多詳細信息將有所幫助〜謝謝

Tkinter程序:沒有顯示底部滾動條

運行您的代碼時,我無法重復該操作。 運行代碼時,我在屏幕底部看到一個巨大的滾動條。

我假設您希望“ x”滾動條是水平的而不是垂直的。 如果是這樣,則必須使用orient選項告訴tkinter:

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

此外,scrollbar.config(command = mylist.yview)是什么意思?

滾動條需要雙向通訊。 列表框需要配置為在滾動時知道要更新的滾動條,並且滾動條需要進行配置以使其知道在移動時要修改的窗口小部件。

當您執行scrollbar.config(command=mylist.yview)您告訴滾動條在用戶嘗試調整滾動條時調用函數mylist.yview .yview方法是Listbox小部件(以及其他一些方法)上的一種記錄方法。 如果未設置滾動條的command屬性,則與滾動條的交互將無效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM