python - Displaying ASCII-art in TKinter -
i trying develop offline version of candy box (solely personal use only) using tkinter , ascii art won't display on tkinter canvas.
this way i'd displayed:
""" .---. | '.| __ | ___.--' ) _.-'_` _%%%_/ .-'%%% a: %%% %% l %%_ _%\'-' | /-.__ .-' / )--' #/ '\ /' / /---'( : \ / | /( /|##| \ | / ||# | / | /| \ \ | ||##| \/ | | _| | ||: | o |#| | / | | || / |:/ / |/ | || | o / / / | \| | |. / / \ /|##| o |.| / \/ \::|/\_ / ---'| """)
and way displayed (i've attempted changing font used in idle (courier, 10), because seemed display correctly, didn't seem help.
using following code, ended looking like:
self.merchantshow = tk.label(self, font=self.fontused, text= """ .---. | '.| __ | ___.--' ) _.-'_` _%%%_/ .-'%%% a: %%% %% l %%_ _%\'-' | /-.__ .-' / )--' #/ '\ /' / /---'( : \ / | /( /|##| \ | / ||# | / | /| \ \ | ||##| \/ | | _| | ||: | o |#| | / | | || / |:/ / |/ | || | o / / / | \| | |. / / \ /|##| o |.| / \/ \::|/\_ / ---'| """) self.merchantshow.grid(row=4, column=0, stick="w")
can please me solve , explain why happening? i'm assuming has font, i'm sure there's got easier way going through fonts.
- align text left (center default)
- backslash @ line end have special meaning in python: wraps long lines. use raw strings
from tkinter import * text = r""" .---. | '.| __ | ___.--' ) _.-'_` _%%%_/ .-'%%% a: %%% %% l %%_ _%\'-' | /-.__ .-' / )--' #/ '\ /' / /---'( : \ / | /( /|##| \ | / ||# | / | /| \ \ | ||##| \/ | | _| | ||: | o |#| | / | | || / |:/ / |/ | || | o / / / | \| | |. / / \ /|##| o |.| / \/ \::|/\_ / ---'| """ root = tk() label(root, justify=left, text=text).pack() root.mainloop()
Comments
Post a Comment