Bonjour
j’ai un petit problème d’affichage d’une chaîne de caractère
dans tkinter les espaces ne sont pas bien pris en-compte
ce qui ne rend pas l’affichage voulue
j’ai fais plusieurs affichage dans label, label frame, canvas .
Mais rien ni fais avez-vous des solutions*?

Merci
ps: j’ai fais un print pour avoir le résultat dans le Terminal

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
#!/usr/bin/env python3
#-*-coding:Utf-8 *-*
 
import tkinter
 
maFenetre = tkinter.Tk()
maFenetre.title("Le canvas")
maFenetre.geometry('600x500')
monTexte="""OOOOOOOOOO
O O    O O
O . OO   O
O O O   XO
O OOOO O.O
O O O    U
O OOOOOO.O
O O      O
O O OOOOOO
O . O    O
OOOOOOOOOO
"""
monCanvas = tkinter.Canvas(maFenetre, width=130, height=200, bg='white')
monCanvas.create_text(50, 110, text=monTexte)
monCanvas.grid(row=0, column=0)
 
monLabel = tkinter.Label(maFenetre, text=monTexte, width=15, height=12)
monLabel.grid(row=0, column=1)
 
monLabelFrame = tkinter.LabelFrame(maFenetre, text=monTexte, width=125, height=190)
monLabelFrame.grid(row=0, column=2)
 
print("Affichage correcte :\n{}".format(monTexte))
 
maFenetre.mainloop()