【问题标题】:python scroll workaroundpython滚动解决方法
【发布时间】:2012-01-08 20:39:50
【问题描述】:

我倾向于在我的 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")

【问题讨论】:

  • 您可能应该提及您使用的 gui 工具包。
  • 这不是一个真正的 Python 问题。
  • 最好包含更多代码,例如您的导入,以便我们运行它。
  • 老实说,如果只给你发布的信息,你有机会理解和解决问题。然后根据你的目标行动。

标签: python text window scroll tkinter


【解决方案1】:

您不能使用带有标签的滚动条。
请改用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()

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 2013-06-01
    相关资源
    最近更新 更多