如何更改tkinter输入字段的宽度或高度

2024-09-19 23:45:10 发布

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

我一直在做一个检查语法的脚本。现在我要用它来更新。问题是,我试图指出语法错误的那一行,而当我使用输入字段输入文本时,所有内容都在一行中。在

我的问题是如何扩展输入字段?

这是我的代码:

import re
from tkinter import *

window = Tk()
window.minsize(width=300, height= 20)
wr = []

def work():
    x = e1.get()
    print(x)
    BigLetterSearcher = re.compile(r'\. .|\n')
    mo = BigLetterSearcher.findall(e1.get())
    x = 1
    y = 0
    v = 0
    z = ""
    wr = []
    for i in mo:
        if i == '\n':
            x += 1
        elif i != i.upper():
            v = 1
            if x != y:
                z = "Row", x
                wr.append(z)
            wr.append(i)
            y = x
    if v == 0:
        wr.append ("Congratulations none of your grammar was wrong!")
    l1.configure(text=wr)

l1 = Label(window, text="example")
e1 = Entry(window, text="Enter text here: ")
b1 = Button(window, text="Work", command=work)

leb = [l1, e1, b1]
for all in leb:
    all.pack()

window.mainloop()

Tags: textinimportrel1forgetif
2条回答

垂直扩展一个输入字段只能通过改变与输入字段相关联的字体大小来完成。。。在

e1 = Entry(window, text="Enter text here: ", font=('Ubuntu', 24))

结果进入的区域比

^{pr2}$

条目小部件无法垂直展开。这是因为已经有一个小部件为此而设计,称为Text()。要将文本添加到文本小部件中,我们可以使用insert(),并使用两部分索引指定位置。第一部分是行,第二部分是列。对于行/行,它从数字1开始,对于该行的索引,它从零开始。在

例如,如果您希望在第一行/列插入内容,您应该执行insert("1.0", "some data here")。在

下面是使用Text()代替的代码。在

import re
from tkinter import *

window = Tk()
window.minsize(width=300, height= 20)
wr = []

def work():
    x = e1.get("1.0", "end-1c")
    print(x)
    BigLetterSearcher = re.compile(r'\. .|\n')
    mo = BigLetterSearcher.findall(x)
    x = 1
    y = 0
    v = 0
    z = ""
    wr = []
    for i in mo:
        if i == '\n':
            x += 1
        elif i != i.upper():
            v = 1
            if x != y:
                z = "Row", x
                wr.append(z)
            wr.append(i)
            y = x
    if v == 0:
        wr.append ("Congratulations none of your grammar was wrong!")
    l1.configure(text=wr)

l1 = Label(window, text="example")
e1 = Text(window, width=20, height=3)
e1.insert("end", "Enter text here: ")
b1 = Button(window, text="Work", command=work)

leb = [l1, e1, b1]
for all in leb:
    all.pack()

window.mainloop()

相关问题 更多 >