【发布时间】:2018-11-16 14:28:39
【问题描述】:
我一直在编写一个几乎是花哨的文本编辑器的应用程序,但在调整其中的小部件大小时遇到了问题。我的目标是让它看起来有点像带有水平滚动条的 IDLE。
from tkinter import *
from tkinter import ttk
root = Tk()
width = preset frame width in relation to root
hieght = preset frame height in relation to root
frame = ttk.Frame(master=root, width=width, height=height)
frame.grid()
frame.grid_propagate(False)
vbar = ttk.Scrollbar(root, orient=VERTICAL)
hbar = ttk.Scrollbar(root, orient=HORIZONTAL)
vbar.grid(row=0, column=1, sticky=N S)
hbar.grid(row=1, column=0, sticky=E W)
text_widget = Text(frame, width=189, height=47, wrap=NONE, undo=True, yscrollcommand=vbar.set, xscrollcommand=hbar.set)
text_widget.grid()
vbar.config(command=text_widget.yview)
hbar.config(command=text_widget.xview)
我正在使用 python 3.7、Windows 10 和 PyCharm。如果您发现此问题的重复,请发表评论并让我在标记为重复和/或关闭之前检查它,因为我还没有找到答案。它有效,只是调整大小是问题。它的行为应该有点像带有自动换行功能的 Windows 记事本。
【问题讨论】:
-
您的代码无法运行。从 ttk 未导入、root 未定义、宽度未定义等开始有许多错误。请阅读this article 并编辑。
标签: python python-3.x tkinter python-3.7