Posts: 76 Threads: 25 Joined: Sep 2020 Sep-15-2020, 12:30 PM (This post was last modified: Sep-15-2020, 12:37 PM by ATARI_LIVE.) Confused the Coding with the font... I use to download the font at: https://www.1001freefonts.com/digital-play-st.font Here code what I am trying: from tkinter import * import pyglet win = Tk() win.geometry("500x200") win.title("FONT TEST") pyglet.font.add_file('/home/pi/.fonts/digital.ttf') set_font=pyglet.font.load('Digital Play St') print(set_font) lab2=Label(win, text="0 1 2 3 4 5 6 7 8 9", font=('set_font',19)) lab2.place(x=10,y=10) win.mainloop() I got the result is NOT what I wanted with the font: Supposed be like this: Thanks for help!!!
I forgot to add, I renamed Digital Play St.ttf to digital.ttf Posts: 8,197 Threads: 162 Joined: Sep 2016 Sep-15-2020, 12:52 PM (This post was last modified: Sep-15-2020, 12:52 PM by buran.) I think you need lab2=Label(win, text="0 1 2 3 4 5 6 7 8 9", font=('Digital Play St',19))https://stackoverflow.com/a/61353191/4046632 Posts: 76 Threads: 25 Joined: Sep 2020 Sep-15-2020, 12:58 PM (This post was last modified: Sep-15-2020, 01:35 PM by ATARI_LIVE.) Thanks for answered, I changed it and same the result. ummm....
Tried different 5 ttf files and make sure ch-mod on those to accessible still no luck. must be something missing in the coding. Tried google no helps. Posts: 8,197 Threads: 162 Joined: Sep 2016 I am at home now and I can test. I am not able to get the expect result on Linux, in Tkinter with just pyglet it works import pyglet pyglet.font.add_file('Digital Play St.ttf') window = pyglet.window.Window() label = pyglet.text.Label('0 1 2 3 4 5 6 7 8 9', font_name='Digital Play St', font_size=36, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') @window.event def on_draw(): window.clear() label.draw() pyglet.app.run()will look further into it Posts: 76 Threads: 25 Joined: Sep 2020 Thank you! it's works... but strange.... My code not work on the raspberry Pi 4B but WORKED on python for window. Posts: 8,197 Threads: 162 Joined: Sep 2016 (Sep-15-2020, 03:12 PM)ATARI_LIVE Wrote: My code not work on the raspberry Pi 4B but WORKED on python for window. I started to suspect that pyglet + tkinter works only on windows - it looks all who claim it works on SO are on windows. by the way, here in the comments it claim file name and font name should be the same in order pyglet to work:https://stackoverflow.com/questions/38815758/adding-downloaded-fonts-to-tkinter So, does pyglet, without tkinter work for you? Posts: 76 Threads: 25 Joined: Sep 2020 (Sep-15-2020, 03:18 PM)buran Wrote: So, does pyglet, without tkinter work for you? Yes, I guess I am go ahead use pyglet then. I am trying to make Alarm Clock with raspberry pi. THANK YOU FOR YOUR HELP! Posts: 76 Threads: 25 Joined: Sep 2020 Ummm... I was trying for clock here the code: import pyglet from pyglet import clock from time import strftime pyglet.font.add_file('/home/pi/.fonts/digital-7.ttf') window = pyglet.window.Window() window.set_fullscreen(False) while True: time_now=strftime('%H:%M:%S %P') label = pyglet.text.Label(time_now, font_name='Digital-7', font_size=300, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') @window.event def on_draw(): window.clear() label.draw() pyglet.app.run()Can do that? Posts: 8,197 Threads: 162 Joined: Sep 2016 Sep-16-2020, 03:49 AM (This post was last modified: Sep-16-2020, 04:00 AM by buran.) you should not use while loop. you need to make a function and call it periodically read more about keeping track of time import pyglet import time pyglet.font.add_file('digital-7.ttf') window = pyglet.window.Window() window.set_fullscreen(False) label = pyglet.text.Label('', font_name='Digital-7', font_size=50, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') def update_clock(dt): label.text = time.strftime('%H:%M:%S %P') pyglet.clock.schedule_interval(update_clock, 0.1) # this will update 10 times a second, you may change that @window.event def on_draw(): window.clear() label.draw() pyglet.app.run() Posts: 76 Threads: 25 Joined: Sep 2020 Sep-16-2020, 10:30 AM (This post was last modified: Sep-16-2020, 10:53 AM by ATARI_LIVE.) Ah it's success!  Thanks! Code here: import pyglet import time i = 2 time_print="%H:%M %P" pyglet.font.add_file('/home/pi/.fonts/Digital-7.ttf') window = pyglet.window.Window() window.set_fullscreen(True) label = pyglet.text.Label('', font_name='Digital-7', font_size=400, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') def update_clock(dt): global i global time_print label.text = time.strftime(time_print) if i == 2: time_print="%H,%M %P" i=1 elif i == 1: time_print="%H:%M %P" i = 2 return pyglet.clock.schedule_interval(update_clock, 1) @window.event def on_draw(): window.clear() label.draw() pyglet.app.run()Also I edited the Digital-7.ttf due to keep center and width to stay with : and ; and 1. (; is blank better than the space). But the pyglet seem more complex than the tkinter. I like tkinter than pyglet more headache for me. I am gonna keep to trying with tkinter because wanted use button and many sizes of fonts each other texts on same the clock screen.
Buran or anyone, if you have time, would you find what's wrong with my original coding with the Tkinter as unable to load the font? My original code does not load the font from the raspberry pi 4B but WORKS on my Python for windows (include exactly copied all modules from raspberry pi to windows) Thank You So Much a Million! |