python滚动解决方案

2024-09-29 23:18:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我倾向于对python程序中与文本相关的所有内容使用标签。在为大约50个引用编写了一个很长的标签之后,我现在只能使用一个多行标签的顶层窗口,需要一个滚动条,而标签不能滚动。在

我把滚动条放在窗口上,但它不滚动。有没有解决办法来上下滚动我的“文本”标签,或者我需要一个不同的小部件放在我的顶层窗口?在

        filewin = Toplevel(background="white")

        scrollbar=Scrollbar(filewin)
        scrollbar.pack(side=RIGHT, fill=Y)
        yscrollcommand=scrollbar.set 


        Label(filewin, text=". . .\n \
    Acidophilium \n\
            Wichlacz,P.L., Unz,R.F., Langworthy,T.A. 1986. Acidiphilium angustum sp. nov. Acidiphilium facilis sp. nov. and Acidiphilium vubrum sp. nov. : \n\
                Acidophilic Heterotrophic Bacteria Isolated from Acidic Coal Mine Drainage. Int J Syst Bacteriol 36:197-201. \n\
    Acinetobacter \n\
            Bouvet,P.J.M., Grimont,P.A.D. 1986. Taxonomy of the Genus Acinetobacter with the Recognition of Acinetobacter baumannii sp. nov. Acinetobacter haemolyticus sp. \n\
                nov. Acinetobacter johnsonii sp. nov. and Acinetobacter junii sp. nov. and Emended Descriptions of Acinetobacter calcoaceticus and Acinetobacter lwofii. \n\
                Int J Syst Bacteriol 36:228-240.",
        justify=LEFT, background="white", foreground="black", wraplength=1000).pack()
        filewin.title("Matrix References")

Tags: andof文本标签spnovpackint
1条回答
网友
1楼 · 发布于 2024-09-29 23:18:15

不能使用带标签的滚动条。
使用Text代替:

from Tkinter import *

root = Tk()

mytext = "Here_your very long text"

scrbar = Scrollbar(root, orient=VERTICAL)
scrbar.pack(side=RIGHT,fill=Y)

text = Text(root, width=80, height=10, state=NORMAL, background="white", foreground="black")
text.insert(INSERT, mytext)
text['state'] = DISABLED
text.pack()

text['yscrollcommand'] = scrbar.set
scrbar['command'] = text.yview

root.title("Matrix References")
root.mainloop()

这会产生(您可能应该调整文本格式):

enter image description here

相关问题 更多 >

    热门问题