ScrolledText 不会一直向下滚动文本框。 Tkinter
ScrolledText doesn't scroll textbox all the way down. Tkinter
所以我得到了这个 python 应用程序,它有一个 UI 用 Tkinter 制作的。
我正在尝试使用以下命令在 UI 中添加一个可滚动的文本框:
text = tkscrolled.ScrolledText(app, width=46, height=20, bg="#e1e2e1", fg="black", highlightthickness = 0, padx=5, wrap=WORD, font=("Arial", 9))
问题是滚动条的大小不是根据文本框的长度确定的(如果我一直向下滚动滚动条,我只看到文本框中内容的一半,但是如果我在鼠标)
我在整个互联网上进行了搜索,大多数解决方案都指向使用 Tkinter 中的其他东西。问题是我不是专业人士,UI 是使用网格系统构建的,而且我不能使用另一个为滚动条添加单独列的库。 也是有办法让它与这段代码一起工作吗?
import os
import tkinter
from tkinter import *
import tkinter.scrolledtext as tkscrolled
import tkinter.messagebox as tkMessageBox
import tkinter.filedialog as tkFileDialog
def closeapp():
app.destroy()
def main_UI(content)
app = Tk()
app.geometry("400x400")
title = Text(app, width=52, height=3, bg="black", fg="white", spacing1=1, spacing3=1, highlightthickness = 0, wrap=WORD, font=("Arial", 9, "bold"))
title.grid(row=0)
title.tag_configure("center", justify="center")
title.insert(INSERT, "\nTitle")
text = tkscrolled.ScrolledText(app, width=50, height=20, padx=5, wrap=WORD, font=("Arial", 9))
text.grid(row=1)
text.insert(INSERT, content)
Button(app, text='Accept', command=accept,bg="#ec6300", fg="white", width=40, font=("Arial", 9, "bold",)).grid(row=2, column=0, pady=4)
Button(app, text='Cancel', command=close,bg="#ec6300", fg="white", width=40, font=("Arial", 9, "bold")).grid(row=3, column=0, pady=4)
app.resizable(False, False)
app.protocol("WM_DELETE_WINDOW", closeapp)
app.mainloop()
return 1
这是我 运行 时的样子:
这是我一直向下使用滚动条时的样子:
但是文本较多,我无法使用滚动条找到它。使用鼠标滚轮滚动将调整滚动条的大小并让我转到文件末尾:
黄色方块是因为我不能分享内容,我只留下一行来证明所有情况都有不同的内容
好像是工具使用的事实.grid()
我删除了所有 grid()
函数并在所有对象上使用了 pack()
。滚动条现在工作正常。
所以我得到了这个 python 应用程序,它有一个 UI 用 Tkinter 制作的。
我正在尝试使用以下命令在 UI 中添加一个可滚动的文本框:
text = tkscrolled.ScrolledText(app, width=46, height=20, bg="#e1e2e1", fg="black", highlightthickness = 0, padx=5, wrap=WORD, font=("Arial", 9))
问题是滚动条的大小不是根据文本框的长度确定的(如果我一直向下滚动滚动条,我只看到文本框中内容的一半,但是如果我在鼠标)
我在整个互联网上进行了搜索,大多数解决方案都指向使用 Tkinter 中的其他东西。问题是我不是专业人士,UI 是使用网格系统构建的,而且我不能使用另一个为滚动条添加单独列的库。 也是有办法让它与这段代码一起工作吗?
import os
import tkinter
from tkinter import *
import tkinter.scrolledtext as tkscrolled
import tkinter.messagebox as tkMessageBox
import tkinter.filedialog as tkFileDialog
def closeapp():
app.destroy()
def main_UI(content)
app = Tk()
app.geometry("400x400")
title = Text(app, width=52, height=3, bg="black", fg="white", spacing1=1, spacing3=1, highlightthickness = 0, wrap=WORD, font=("Arial", 9, "bold"))
title.grid(row=0)
title.tag_configure("center", justify="center")
title.insert(INSERT, "\nTitle")
text = tkscrolled.ScrolledText(app, width=50, height=20, padx=5, wrap=WORD, font=("Arial", 9))
text.grid(row=1)
text.insert(INSERT, content)
Button(app, text='Accept', command=accept,bg="#ec6300", fg="white", width=40, font=("Arial", 9, "bold",)).grid(row=2, column=0, pady=4)
Button(app, text='Cancel', command=close,bg="#ec6300", fg="white", width=40, font=("Arial", 9, "bold")).grid(row=3, column=0, pady=4)
app.resizable(False, False)
app.protocol("WM_DELETE_WINDOW", closeapp)
app.mainloop()
return 1
这是我 运行 时的样子:
这是我一直向下使用滚动条时的样子:
但是文本较多,我无法使用滚动条找到它。使用鼠标滚轮滚动将调整滚动条的大小并让我转到文件末尾:
黄色方块是因为我不能分享内容,我只留下一行来证明所有情况都有不同的内容
好像是工具使用的事实.grid()
我删除了所有 grid()
函数并在所有对象上使用了 pack()
。滚动条现在工作正常。