首页 > 解决方案 > 如何在 Tkinter、Python 3.8 中创建文本 wiget

问题描述

我想在窗口中制作一个文本wiget,但看到了这个回溯:

Traceback (most recent call last):
  File "D:/хрень на питоне/experement3.py", line 18, in <module>
    vl=Text(root, width = 20, heigth = 100 , wrap = WORD)
  File "C:\Users\Людмилп\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3554, in __init__
    Widget.__init__(self, master, 'text', cnf, kw)
  File "C:\Users\Людмилп\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2567, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-heigth"

我的代码如下所示:

from tkinter import *
root=Tk()
root.geometry('400x300')
app=Frame(root)
app.grid(row=2,column=0,sticky=S)
bt=Button(app,text='''
First button
''')
bt.grid()
app1=Frame(root)
app1.grid(row=2,column=1,sticky=S)
bt1=Button(app1,text='''
Second button
''')
bt1.grid()
vlf=Frame(root)
vlf.grid(row=0,column=3)
vl=Text(root, width = 20, heigth = 100 , wrap = WORD)
vl.grid()
root.mainloop()

可能出了什么问题?

标签: python-3.xtkinter

解决方案


请仔细阅读您的错误消息,因为它们几乎包含有用的信息。在这种情况下,它会告诉您在第 18 行初始化 Text 小部件的位置,您给它一个选项“heigth”,它不能接受。这是因为您只是通过切换“t”和“h”而拼错了“height”,这可能会发生并且只是人类。

PS:你的英文还不错,别担心。^^


推荐阅读