ProgrammingNinja
ProgrammingNinja

Reputation: 27

How to separate text in label which uses a Variable size

My program takes a users input, the input can be quite long, part of the program is too display that text, so far i have manager to get the text to be shown, however, the text carries out off the fixed size screen

how can i get my program to seperate the text so that it can only go so far and then the message continues on the next line image shows part of the intended message

    cursor.execute(findPlayerTeamname, [(playerTeamname)])
    temp = cursor.fetchall()
    temp = temp[0][0]

    message = StringVar()
    message.set(temp)

    messageLabel = Label(canvas, text = "Notice:")
    messageLabel.place(x = 30, y = 60)
    messageLabel.configure(bg = "grey90", fg = "royalblue", font=("Arial Nova", 25))    

    updatedMessageLabel = Label(canvas, textvariable = message)
    updatedMessageLabel.place(x = 30, y = 120)
    updatedMessageLabel.configure(bg = "grey90", fg = "royalblue", font=("Arial Nova", 16))

Upvotes: 0

Views: 101

Answers (1)

Henry Yik
Henry Yik

Reputation: 22503

You can use the textwrap module.

from tkinter import *
import textwrap

root = Tk()
text = "This is a very long sentence that needs wrapping else it will run out of space"
Label(root,text=textwrap.fill(text,20)).pack()

root.mainloop()

Upvotes: 1

Related Questions