Python Forum
[Tkinter] Lock Text Widget height
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Lock Text Widget height
#1
Hello everybody,

I've searched for hours and I can't manage to find something, I hope that one of you may help me...

What I'm trying to do is to limit the height of a text box widget in Tkinter. Because for the moment with my code, I can set the height of the text box (25 lines for example). But when I type my text into the text box and I reach the line 25, if I keep on writing, it keeps creating new lines of text. What I would want is to lock the height so the user can just type 25 lines of text and cannot write infinitely.

Here is the GUI Part of my program :

import tkinter as tk
from tkinter import ttk

fenetre = Tk()
fenetre.title("test")
fenetre.tk.call('wm', 'iconphoto', fenetre._w, tk.PhotoImage(file='test.png'))

def lignevide() :
    lignevide = Label(fenetre, text="" ,fg="red", font ="Arial" ,height ="1")
    lignevide.pack()

scrollbar = Scrollbar(fenetre)
scrollbar.pack(side='right', fill='y')

texte1 = Label(fenetre, text="Tapez votre texte à imprimer :" ,fg="black", font =("Montserrat" ,22) ,height ="1",)
texte1.pack()

texte2 = Label(fenetre, text= "Attention, les chiffres, les majuscules et certains caractères spéciaux ne sont pas imprimables !" ,fg="red", font =("Montserrat" ,10) ,height ="1",)
texte2.pack()

lignevide()

saisie = Text(fenetre, width = 25 ,height = 23, font="Arial" ,highlightcolor = "black" ,highlightbackground = "yellow", relief="flat", yscrollcommand = scrollbar.set)
saisie.pack()


lignevide()

bouton = ttk.Button(fenetre, text="Confirmer", command=retrieve_input)
bouton.pack()

lignevide()

bouton2 = ttk.Button(fenetre, text="Annuler et quitter", command=fin)
bouton2.pack()

lignevide()

fenetre.mainloop()
Thanks to anyone that would help me !
Reply


Messages In This Thread
Lock Text Widget height - by Oxylium - Feb-14-2019, 07:42 PM
RE: Lock Text Widget height - by woooee - Feb-14-2019, 08:00 PM
RE: Lock Text Widget height - by Oxylium - Feb-14-2019, 08:11 PM
RE: Lock Text Widget height - by woooee - Feb-14-2019, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 10,916 Jun-26-2022, 06:26 PM
Last Post: menator01
  Tkinter reduce OptionMenu height euras 2 6,582 May-25-2021, 09:14 PM
Last Post: euras
  [Tkinter] Text widget inert mode on and off rfresh737 5 5,875 Apr-19-2021, 02:18 PM
Last Post: joe_momma
  Line numbers in Text widget rfresh737 3 8,336 Apr-15-2021, 12:30 PM
Last Post: rfresh737
  tkinter text widget word wrap position chrisdb 6 10,916 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  Check for Caps Lock ebolisa 1 3,521 Dec-29-2020, 10:41 PM
Last Post: Larz60+
  [Tkinter] Get the last entry in my text widget Pedroski55 3 8,934 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to place global tk text widget in class or on canvas puje 1 3,258 Jul-04-2020, 09:25 AM
Last Post: deanhystad
  Treeview - How to lock columns taratata2020 0 4,314 Mar-29-2020, 03:30 PM
Last Post: taratata2020
  Tkinter - Need Help setting Height of a TextInputBox itslewis 1 2,170 Mar-22-2020, 02:37 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020