Set width and height in text box

Asked

Viewed 3,733 times

4

To expand knowledge, I decided to start a new programming language, Python, and locked in the following situation, I have a screen with some elements and a text box of type Entry.

inserir a descrição da imagem aqui

To define the text box, I used the following code:

self.form = Entry(self.frame2)
self.form.pack()

I did some basic research, however the staff changes Entry for Text and defines width and heigth. I tried to use, but at the time I use form.get() to capture the text, an error appears:

Typeerror: get() Missing 1 required positional argument: 'index1'

Would you like to know how to set width and height of the Entry?

  • Wrong tag...the problem is not with python, but with the Tkinter module.

3 answers

2


The tkinter.Entry only lets you set the width. Alternatively the tkinter.Text which makes such changes.

Typeerror: get() Missing 1 required positional argument: 'index1'

Other than tkinter.Entry.get which returns all the contents of Entry, the tkinter.Text.get returns the characters that are within a range, start and end, if end is omitted, only one character is returned. The message indicates that you must provide at least one argument, start.

To get all the content, do so:

conteudo = texto.get(1.0, END)

Take an example:

from tkinter import *

root = Tk()
root.title('Calculadora')
root.geometry('300x300')

texto = Text(root, height = 4, width = 15)
texto.insert(INSERT, 'foo bar')
texto.pack()

conteudo = texto.get(1.0, END)
print (conteudo)

root.mainloop()
  • What represents the 1.0?

  • @seamusd The first character.

  • Validated the answer! Hugs.

0

You could use the place like this by passing the vestments like in the example:

from tkinter import*

janela = Tk ()

janela.geometry("300x400")

#criando o Entry()

E = Entry(janela)

**# função place alterar posição do frame na tela relativo x e y e relwidth a largura e relheight a altura**

E.place(relx = 0.1, rely = 0.1,relwidth = 0.8,relheight=0.11)

janela.mainloop()

-1

To have a text box that can increase the height, you need to use the tkinter.tix, is an extension of tkinter, in it there are numerous other visual objects, the LabelEntry If I remember, it allows the input of text and the to increase its width and its height.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.