'Cannot change tkinter font on pixelbook
I am using python3 with tkinter on my pixelbook chromebook using native Linux in developer branch. It's an Anaconda distribution (python 3.6.5), and all packages work as expected, except this small kink in tkinter. The default font size in tkinter is extremely small, and I cannot change it for some reason. Here is a simple code that I try:
from tkinter import *
root = Tk()
root.wm_title("Tkinter Testing")
l = Label(root, text='Hello config world', font=('Helvetica', 60))
l.pack()
root.mainloop()
The resulting window:
- has no title
- has something like 2pt font, barely legible.
I am sorry that you have to just take my word for it, but I don't have the rank required to embed pictures.
I have tried all sorts of fonts: "Helvetica", "Veranda", "times", also "TkFixedFont", "TkHeadingFont", and nothing makes any difference. I don't get any errors, not even when I enter something like this: "asdfe". It just doesn't care.
I can run
from tkinter import font
and it succeeds, so that's not a problem. Could I be missing some font packages? What could be different about my pixelbook Linux environment from a standard Ubuntu? When I take my code from pixelbook and run it on Windows the font scales as expected and I get the title, so it's not the code, it's the environment.
Solution 1:[1]
When I use tkinter fonts here is some of the code I use:
from tkinter import Font as tkFont
helvetica = tkFont.font(family = "Helvetica", size = 12)
Label(... font = helvetica)
If you pre-define fonts, then you can reuse then and change them easily.
To fix your problem, change this:
font = ("Helvetica", 60)
to this:
font = tkFont.Font(family = "Helvetica", size = 60)
FYI: The original code worked just fine on my Raspbian Raspberry Pi.
Solution 2:[2]
Hey there i think you need to keep it as a ""
You can also see if the font is installed on your device
from tkinter import *
root = Tk()
root.wm_title("Tkinter Testing")
l = Label(root, text='Hello config world', font='Helvetica 60')
l.pack()
root.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | cs1349459 |
Solution 2 | Aninet |