Reputation: 1323
How? I've tried several variations of
self.textindex = self.canvastext.create_text(0,696,font=('freemono bold',9), anchor='nw', fill='black', text='Longitude: ' + str(px))
or
self.textindex = self.canvastext.create_text(0,696,font=('bold', 'freemono bold',9), anchor='nw', fill='black', text='Longitude: ' + str(px))
etc, to either have the font type revert back to the default font or to give me errors.
I actually want some type of font that is block style font, every character has the same width, so I can setup up nice column style formatting on parts of the screen. I don't see on any programs I run, Times Roman(I think that is the right name) pop up so I'm guessing Linux Mint doesn't come standard with it:)..hence using freemono. I would stick with the default font, which is already bold, trying to format it on the screen is a lot more difficult though and I'm in kinda for the looks given how nicely this program is turning out right now.
Upvotes: 2
Views: 10731
Reputation: 143
this worked for me (Python 3):
canvas.create_text(x, y, font=('freemono', 11, 'bold'), anchor='sw', text=s)
And in addition to Bryan's answer: if you're using tkinter (as opposed to Tkinter) your code is:
from tkinter import font
...
myfont = font.Font(family='freemono', size=11, weight="bold")
canvas.create_text(x, y, font=myfont, anchor='sw', text=s)
Upvotes: 2
Reputation: 385900
The best way is to create a font object. For example:
# python2
import Tkinter as tk
import tkFont as tkfont
# python3
# import tkinter as tk
# from tkinter import font as tkfont
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400, background="bisque")
canvas.pack(fill="both", expand=True)
normal_font = tkfont.Font(family="Helvetica", size=12)
bold_font = tkfont.Font(family="Helvetica", size=12, weight="bold")
canvas.create_text(50,50, text="This is normal", font=normal_font)
canvas.create_text(50,100, text="This is bold", font=bold_font)
root.mainloop()
Upvotes: 4
Reputation: 11
instead of changing the weight of the letters, you could change the font of the letters by saying (font="Ariel") but with the font that is thick enough for you. Hope this helped :)
Upvotes: 0