How to force Tkinter text widget to stay on one line?



Tkinter text widget can be configured by using the configure(**options) function. We can use it to configure the background color, foreground color, wrapping and other properties of the text widget.

The wrap properties of the Text widget describe that the cursor changes its position whenever it detects a new line. However, in Tkinter, the text widget can be wrapped by words and characters. In order to make our text widget to stay in one line, we can use wrap=None property.

Example

# Import the required libraries from tkinter import * import lorem # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Add a Text widget text=Text(win, width=60, height=20) text.pack() # Add Some text into it text.insert(END,lorem.sentence()) # Configure the text widget to make the text sticky on one line text.configure(wrap=None) win.mainloop()

Output

Running the above code will display a text widget that will have its text wrapped to None.

Updated on: 2021-06-18T14:17:53+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements